在ES指数中以下列格式给予 JSON:
{
"pin": {
"id": 123,
"location": {
"lat": 456,
"lon":-789
}
}
}
以下获取匹配 id
字段的文档 :
client.prepareSearch("index_name")
.setTypes("pin")
.setQuery(QueryBuilders.termQuery("id", 123))
.execute()
.actionGet();
相反,我试图匹配多个字段,即( place.lat
, place.lon
)。
QueryBuilders.termQuery(); // accepts only a single term
尝试的替代方法不多,但似乎没有奏效,例如:
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();