考虑以下指标结果: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
要使嵌套查询正常工作,您需要嵌套映射,但您没有大概。可以添加映射吗?如果没有,上述查询无法正常工作。 –