0

Is there a way to query elastic search for all documents that contain the value of one property in the multivalued field; i.e.:

I have a list of property values in field COLORS: Red, Blue, Black, Green another property has a single value in field PREFERENCE : Red

is there a way to select all documents that contain value found in field PREFERENCE within the multi valued field COLORS?

SQL equivalent would be something of this sort:

SELECT * FROM index WHERE COLORS LIKE CONCAT('%', PREFERENCE, '%')
Alex Smirnov
  • 537
  • 1
  • 5
  • 12

1 Answers1

1

You could use a script filter. Something like this

GET /test/stack/_search
{
    "query": {
        "match_all": {}
    },
    "filter": {
        "script":{ 
           "script":"if(doc['colors'].values.indexOf(doc['preference'].value) > -1) true; else false;" ,
           "params": {}

        },"lang":"js"
    }
}
user3340677
  • 177
  • 1
  • 4