Given the JSON in the ES index in the following format:
{ "pin": { "id": 123, "location": { "lat": 456, "lon":-789 } } }
The following gets the document corresponding to the id
field:
client.prepareSearch("index_name") .setTypes("pin") .setQuery(QueryBuilders.termQuery("id", 123)) .execute() .actionGet();
Instead, I'm trying to match multiple fields, i.e. ( location.lat
, location.lon
).
QueryBuilders.termQuery();
I tried several alternatives, but none of them work, for example:
QueryBuilder queryBuilder = QueryBuilders.boolQuery() .must(QueryBuilders.termQuery("location.lat", 456)) .must(QueryBuilders.termQuery("location.lon", -789)); client.prepareSearch("index_name") .setTypes("pin") .setQuery(queryBuilder) .execute() .actionGet();
source share