Reputation: 21
My search query looks like this:
curl -XGET "http://localhost:9200/imagesearchservice/images /_search?pretty=true" -d '
{
"query": {
"bool": {
"must": [
{
"nested": {
"path":"tags",
"query": {
"bool": {
"must": [
{"match_all" : {} }
],
"filter" : {
"terms" : {
"tags.tagName" : ["star"]
}
}
}
}
}
}
]
}
}
}'
I tried doing the following but it didnt work.
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
.withFilter(boolQuery().must(termsQuery("tags.tagName", tagNames)))
.build();
I am using Elastic Search v2.x . Can someone please tell me how to build a search query for the above using nativesearchquerybuilder ?
Upvotes: 0
Views: 958
Reputation: 163
I would do something like this:
BoolQueryBuilder booleanQuery = new BoolQueryBuilder();
booleanQuery.must(termsQuery("tags.tagName", tagNames));
myElasticSearchRepository.search(booleanQuery)
Where myElasticSearchRepository is an interfce that extends ElasticsearchRepository
Upvotes: 1