Send an array of string in query and get all the documents in which the field value matching with any of the array element value

Currently, my documents in my index has data like this

  {
        "_index" : "traffic",
        "_type" : "_doc",
        "_id" : "dYY7m3AB_cmkU5saDRdM",
        "_score" : 4.078947,
          "keyword" : "baby toothpaste 0-2 years organic",
          "region" : "uk"
        }
{
        "_index" : "traffic",
        "_type" : "_doc",
        "_id" : "dYY7m3AB_cmkU5saDRdM",
        "_score" : 4.078947,
          "keyword" : "baby toothpaste",
          "region" : "uk"
        }
{
        "_index" : "traffic",
        "_type" : "_doc",
        "_id" : "dYY7m3AB_cmkU5saDRdM",
        "_score" : 4.078947,
          "keyword" : "toothpaste",
          "region" : "uk"
        }

now I want to pass a list of string like
{"toothpaste", "baby toothpaste"} and get the documents that exactly match the give keyword value

don't want partial matching so went with term query but in term query
I can send only a single value and not an array of value
but sending an array list of values is not possible

I achieved this previously by using match query by sending a string which contains all the keywords separated by commas like this "toothpaste, baby toothpaste" but here the strict matching didn't happen and some other documents also came like even the data like because of partial matching
"baby toothpaste 0-2 years organic" came as toothpaste was in it

and this made only one request and I got all the data
but if have to use term query then I have to make n request for n keywords

Is there any better way like sending an array or I should I get all the data even partially matched and filter in java code

java code :-
boolQuery.must(QueryBuilders.termQuery("keyword.keyword", keyword));

Thanks for your help

I found the solution so there are also terms Query which takes a collection
as input which is exactly what I wanted
, therefore, changing my java code to did the trick
boolQuery.must(QueryBuilders.termsQuery("keyword.keyword", keyword));

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.