Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

321
Vistas
elasticsearch ajax call error

I try to use elasticsearch with an ajax call in my jquery webpage but I fail to make it work...

here is my ajax query :

var data = {
                query:{match:{_all:10}},
                fields: 'DEPET'
                };
            $.ajax({
                type : 'POST', // envoi des données en GET ou POST
                url : 'http://localhost:9200/_search' , // url du fichier de traitement
                crossDomain: true,  
              async: false,
              data: JSON.stringify(data),
              dataType : 'json',
                beforeSend : function() { // traitements JS à faire AVANT l'envoi
                    $('#ajax-loader2').append('<img src="/dev/wp-content/themes/codium-dn/images/ripple.gif" alt="loader" id="ajax-loader" />');
                },
                success : function(data){ // traitements JS à faire APRES le retour d'ajax-search.php
                    $('#ajax-loader').remove(); // on enleve le loader
                    $('#results').html(data); // affichage des résultats dans le bloc
                    console.log(data);
                },
                error: function (data, error) {
                    console.log(arguments);
                    //alert(" Can't do because: " + error);
                }
            })

I also put this in my elasticsearch.yml

http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-credentials: true
http.cors.allow-headers: "X-Requested-With, Content-Type, Content-Length, Authorization"
http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE

And this is what the console chrome dev give me :

(index):451 (3) [Object, "error", DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://localhost:9200/_s…, callee: function, Symbol(Symbol.iterator): function]

Request URL:http://localhost:9200/_search
Referrer Policy:no-referrer-when-downgrade
Request Headers
Provisional headers are shown
Accept:application/json, text/javascript, */*; q=0.01
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Origin:https://domain.ovh
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.33 Safari/537.36
Form Data
view source
view URL encoded
{"query":{"match":{"_all":10}},"fields":"DEPET"}:

Thanks for your inputs

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Try out this

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://localhost:9200/_search",
  "method": "POST",
  "headers": {
    "cache-control": "no-cache",
    "postman-token": "c24112d5-9dc4-0230-7954-01064b61be5c"
  },
  "data": "{\r\n  \"query\": {\r\n    \"match_all\": {}\r\n  }\r\n}\r\n"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

I have used postman tool to generate this code.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda