I am searching the index object based on the lat long (geo_point type) for a distance of 999km and I am sorting it on the ascending order.
But I am getting the exception Elasticsearch exception [type=parsing_exception, reason=[_geo_distance] does not support [ignore_unmapped]]
I am using elasticsearch version 6.3.0 alothough the same code is working fine in version 6.4.0. Is there anyway I can make it work in version 6.3.0
Here is the code that is searching and sorting.
QueryBuilder queryBuilder = boolQuery().filter(
QueryBuilders
.geoDistanceQuery(LOCATION)
.point(Double.parseDouble(latitude),Double.parseDouble(longitude))
.distance(Double.parseDouble(range), DistanceUnit.KILOMETERS)
);
GeoDistanceSortBuilder sortBuilderAsc = SortBuilders.geoDistanceSort("location", new Double(latitude), new Double(longitude))
.order(SortOrder.ASC)
.unit(DistanceUnit.KILOMETERS)
.sortMode(SortMode.MIN);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(queryBuilder).sort(sortBuilderAsc);
SearchRequest searchRequest = new SearchRequest(index);
searchRequest.source(searchSourceBuilder);
searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH);
SearchResponse response = getClient().search(searchRequest, RequestOptions.DEFAULT);
This is the index mapping
{
"buildings": {
"mappings": {
"esbuilding": {
"properties": {
"addressStreet1": {
"type": "text"
},
"addressStreet2": {
"type": "text"
},
"buildingName": {
"type": "text"
},
"city": {
"type": "text"
},
"location": {
"type": "geo_point"
},
"state": {
"type": "text"
}
}
}
}
}
}
Here is the search JSON that is generated from the above Java Code for a given lat long.
{
"sort" : [
{
"_geo_distance" : {
"location": [
-71.588822,
42.333777
],
"order" : "asc",
"unit" : "km",
"mode" : "min",
"distance_type" : "arc",
"ignore_unmapped": true
}
}
],
"query": {
"bool": {
"filter": [{
"geo_distance": {
"location": [
-71.588822,
42.333777
],
"distance" : 999000.0,
"distance_type": "arc",
"validation_method": "STRICT",
"ignore_unmapped": false,
"boost": 1.0
}
}],
"adjust_pure_negative": true,
"boost": 1.0
}
}
}
Stack trace:
org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=parsing_exception, reason=[_geo_distance] does not support [ignore_unmapped]]
at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177)
at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:1406)
at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:1382)
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1269)
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1231)
at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:730)
at com.trimble.engage.search.repository.ElasticSearchRepository.searchByQueryAndSort(ElasticSearchRepository.java:64)
Is there anyway I can remove the field "ignore_unmapped" from the above java code. If I remove the field ignore_unmapped, it is working fine in version 6.3.0