0

I try to find out how to build the following query with elasticsearch java api

{
  "query": {
    "bool": {
      "must": [
        {
          "terms_set": {
            "names": {
              "minimum_should_match_field": "some_match_field",
              "terms": [
                "Ala",
                "Bob"
              ]
            }
          }
        }
      ]
    }
  }
}

I tried to build this query with following code, but there is no termsSetQuery method as well as minimumShouldMatchField in api.

        NativeSearchQuery build = new NativeSearchQueryBuilder()
            .withQuery(boolQuery()
                    .must(termsQuery("names", List.of("Ala", "Bob"))))
            .build();

but it results as below

{
  "bool": {
    "must": [
      {
        "terms": {
          "names": [
            "Ala",
            "Bob"
          ]
        }
      }
    ]
  }
}

1 Answer 1

3

You need to use TermsSetQueryBuilder for creating query like below:

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
List<String> terms = new ArrayList<>();
terms.add("Ala");
searchSourceBuilder.query(QueryBuilders.boolQuery()
                .must(new TermsSetQueryBuilder("names", terms).setMinimumShouldMatchField("some_match_field")));
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.