0

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 ?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.