鑑於JSON在ES指數採用以下格式:Elasticsearch QueryBuilder的匹配多個條款
{
"pin": {
"id": 123,
"location": {
"lat": 456,
"lon":-789
}
}
}
下獲得匹配的id
領域的文檔:
client.prepareSearch("index_name")
.setTypes("pin")
.setQuery(QueryBuilders.termQuery("id", 123))
.execute()
.actionGet();
相反,我試圖匹配多個領域,即。 (location.lat
,location.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();
是位置索引爲geo_point? – imotov
是的,它被映射爲'geo_point'。 – ahmedyha