'Build terms_set query in elasticsearch java api
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"
]
}
}
]
}
}
Solution 1:[1]
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")));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sagar Patel |
