How do I implement a terms query like under in Java? Anyway to use termsQuery() or other way?
{
"terms": {
"model_id": [
"166168N",
"753547",
"1568357",
"90112",
"1020682",
"3257438"
],
"boost": 1.0E 6
}
}
CodePudding user response:
You can create query like below using Java high level client:
SearchRequest searchRequest = new SearchRequest("userdoc");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
String[] values = new String[] { "166168N", "753547", "1568357", "90112", "1020682", "3257438" };
searchSourceBuilder.query(new TermsQueryBuilder("model_id", values).boost(1));
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);