I am trying to query elastic search which has the following record:
{
"_index": "my-index",
"_type": "v1",
"_id": "8758",
"_source": {
"id": "5855",
"version": 3,
"createdAt": "2020-10-30T04:45:32Z",
"location": {
"country": "CA",
"provinceCode": "NA",
"zipCode": "6069",
"address1": "Some Address",
"latLong": {
"lon": 150.890033,
"lat": -24.794214
}
}
}
}
with the following curl request:
curl --location --request GET 'http://localhost:9200/my-index/_search' \
--header 'Content-Type: application/json' \
--data-raw '{
"_source" : {
"include": "*"
},
"sort": {
"_script": {
"type": "number",
"script" : {
"lang": "painless",
"source": "Math.round((doc[params.field].planeDistanceWithDefault(params.lat, params.lon, 0) * 0.001) * 100.0) / 100.0",
"params" : {
"lat" : -25.8152,
"lon" : 150.0912,
"field": "location"
}
}
}
}
}'
getting following error:
"caused_by": {
"type": "illegal_argument_exception",
"reason": "No field found for [location] in mapping with types []"
}
My questions are:
- Why is ES query not finding location field?
- Is there I need to change in my curl request to make it work?