Help to convert SQL to ElasticSearch

Hey guys,

can somone help me to convert this sql query to elasticsearch query:

SELECT id, supplier FROM s_articles WHERE supplier NOT IN (1,2) OR id IN (1,2,3,4,5,6)

What have you tried so far?

I have tried to use should => must_not and should, but its not working.
Everything i try its not working..

Last query i have tried:

{
	"query": {
			"bool":{
				
				"should":{
					"bool":{
						"must_not":[
							{"term":{"supplier":1}},
							{"term":{"supplier":2}}
						],
						"should":[
							{"term":{"id":1}},
							{"term":{"id":2}},
							{"term":{"id":3}},
							{"term":{"id":4}},
							{"term":{"id":5}},
							{"term":{"id":6}}
						]
					}
				}
			}
		}
		
}

I have found the solution, thanks

Can you share it, it might help someone in the future :slight_smile:

Ofcourse, this is an solution.

{
	"query" : {
		"bool":{
			"should":[
					{
						"bool":{
							"must_not":[
								{"term":{"supplier":1}},
								{"term":{"supplier":2}}
							]
						}
					},
					{
						"bool":{
							"should":[
								{"term":{"id":1}},
								{"term":{"id":2}},
								{"term":{"id":3}},
								{"term":{"id":4}},
								{"term":{"id":5}},
								{"term":{"id":6}}
							]
						}
					}
			]
		}
	}
}
1 Like

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