Given the following index result:
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
}
}
...
Now I want to do a search and get all entries matching two fields, e.g. list.value=SomeValue123 && list.type=SomeType123. The problem is, that the result may be huge, so scrolling should be possible.
What I have so far:
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;
}
}
But all I get is a:
Caused by: org.elasticsearch.index.query.QueryParsingException: [nested] failed to find nested object under path [list]
How can I get all items, that match this fields combination with the elastic search java client?
If someone knows just the curl command, that would be fine, so I can use templates!
do...while()loop insteed of breaking out ;)