考慮以下指標結果:Elasticsearch嵌套數組或什麼是嵌套數組的路徑?
curl 'localhost:9200/index123/type123/_search?q=*&pretty'
...
"_source": {
"objectId": "objectId123",
"list": [{
"name": "SomeName123",
"value": "SomeValue123",
"type": "SomeType123"},
{"name": "SomeOtherName123", ...}],
"someOther": {
"i": "i",
"value": 3
}
}
...
現在我想做一個搜索,並得到所有條目匹配兩個字段,例如list.value = SomeValue123 & & list.type = SomeType123。問題是,結果可能很大,所以應該可以滾動。
我到目前爲止有:
SearchResponse scrollResp = elasticSearchClient
.prepareSearch("index123")
.setTypes("type123")
.setScroll(new TimeValue(60000))
.setQuery(
QueryBuilders.nestedQuery(
"list",
QueryBuilders
.boolQuery()
.must(QueryBuilders.matchQuery("value", "SomeValue123"))
.must(QueryBuilders.matchQuery("type", "SomeType123")))
)
.setSize(100)
.execute()
.actionGet();
SomeQueue<SomeBean> resultQ= new SomeQueue<SomeBean>();
// Scroll until no hits are returned
while (true) {
resultQ.offer(getObjectOutOfHits(scrollResp.getHits().getHits()));
scrollResp = elasticSearchClient
.prepareSearchScroll(scrollResp.getScrollId())
.setScroll(new TimeValue(60000))
.execute()
.actionGet();
// Break condition: No hits are returned
if (scrollResp.getHits().getHits().length == 0) {
break;
}
}
但我得到的是:
Caused by: org.elasticsearch.index.query.QueryParsingException: [nested] failed to find nested object under path [list]
如何,我可以得到的所有項目,那場比賽這一領域用的彈性搜索Java客戶端結合?
如果有人知道只是curl命令,那很好,所以我可以使用模板!
點點offtopic,但你可以使用'做......而()爆發的'循環insteed;) – Antoniossss
你是對的,但我只是複製從滾動例如該代碼HTTPS ://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search-scrolling.html – hiaclibe
要使嵌套查詢正常工作,您需要嵌套映射,但您沒有大概。可以添加映射嗎?如果沒有,上述查詢無法正常工作。 –