Elasticsearch query with jQuery/Ajax Elasticsearch query with jQuery/Ajax elasticsearch elasticsearch

Elasticsearch query with jQuery/Ajax


Okay, problem resolved. My code is okay. I changed method to "POST". Using Google Chrome Developer Tools I noticed that the other part of code wasn't good. In my code

"location": {    "lat" :  40.715,   "lon": -73.998}

lat and lon was a variables (I changed them to coords for StackOverflow question) wchich was empty, because the other part of my code couldn't assign a new value from getCurrentPosition() (default value was 0, that's why my code didn't work). So, correct version of the code is:

var data = {  "query": {    "filtered": {      "filter": {        "geo_distance": {          "distance": "1km",           "location": {             "lat" :  lat,            "lon": lon          }        }      }    }  }}$.ajax({  method: "GET",  url: "http://localhost:9200/locations/_search?pretty=true",  crossDomain: true,    async: false,  data: JSON.stringify(data),  dataType : 'json',  contentType: 'application/json',}).done(function( data ) {  console.log(data);}).fail(function( data ) {  console.log(data);});

Notice that lat and lon are variables which need parameters to be a geopoint