Skip to content
Advertisement

Combine OR, AND and IN operators in Elasticsearch query

I am very new to the elasticsearch and I need to prepare the query which combines OR, AND and IN operators. What I want to achieve is having something like this in SQL:

SELECT * FROM tableWHERE (field_1 = 'foo' AND field_2 IN(1,2,3) ) OR ('field_1 = 'bar' AND field_2 IN(2, 3, 4) );

I am using elastic with PHP and have started with something like this:

JavaScript

However, I cannot add query parameters to achive my desired result. Can you please help me with that?

Advertisement

Answer

You need to combine bool/must/should query clauses. For IN operator you can use terms query in elasticsearch

Try out this below query

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement