How to find an element in an array with elasticsearch

Viewed 82

I have one array like ["a", "b", "c"] in my DB (mysql) and I want to get all those rows that include "a". How can I do that with elasticSearch and Go?

My code is the following:

query.Must(elastic.NewTermsQuery("Visibility",[]string{"a"}))

This doesn't work and I couldn't find anything on internet about this, until now. What do you think I have to do?

1 Answers

Could you share the mapping of the index and the sample document ? the terms query should work for the array.

The query you are building in Go should work. You don't even need must unless you have another query.

{
 "query" :{
    "terms" : {
       "visibility": ["a"]  
     }
  }
}
Related