07-30-2023, 02:18 PM
Given JSON in ES index in the following format:
{
"pin": {
"id": 123,
"location": {
"lat": 456,
"lon":-789
}
}
}
The following gets the document matching the `id` field:
client.prepareSearch("index_name")
.setTypes("pin")
.setQuery(QueryBuilders.termQuery("id", 123))
.execute()
.actionGet();
Instead, I 'm trying to match multiple fields, ie. (`location.lat`, `location.lon`).
QueryBuilders.termQuery(); // accepts only a single term
Tried few alternatives but none of it seems to work, eg:
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();
{
"pin": {
"id": 123,
"location": {
"lat": 456,
"lon":-789
}
}
}
The following gets the document matching the `id` field:
client.prepareSearch("index_name")
.setTypes("pin")
.setQuery(QueryBuilders.termQuery("id", 123))
.execute()
.actionGet();
Instead, I 'm trying to match multiple fields, ie. (`location.lat`, `location.lon`).
QueryBuilders.termQuery(); // accepts only a single term
Tried few alternatives but none of it seems to work, eg:
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();