Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
error de llamada elasticsearch ajax

Intento usar elasticsearch con una llamada ajax en mi página web jquery pero no logro que funcione...

aquí está mi consulta ajax:

 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); } })

También puse esto en mi 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

Y esto es lo que me da la consola Chrome Dev:

 (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"}:

gracias por tus aportes

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

prueba esto

 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); });

He usado la herramienta Postman para generar este código.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!