feicipet
feicipet

Reputation: 954

Elasticsearch query for "OR but not ALL"

My ES document looks like this:

Data Sample

where ResponseQ1, ResponseQ2 and ResponseCompleted are integers and the rest are string text.

I need to create a query with the condition where either 1 or 2 (BUT not all 3) sub-conditions are fulfilled:

  1. ResponseQ1:0
  2. ResponseQ2:0
  3. ResponseQ3:"skipped"

Doing a bool query with "should" can easily get me a simple OR relationship where 1, 2 or 3 of the subconditions are met, but I simply cannot figure out how to fulfill the "BUT not all 3 subconditions".

Would really appreciate some pointers on this, thanks.

I'm using ElasticSearch 2.2 running my queries through Kibana 4.4.1.

Upvotes: 0

Views: 62

Answers (1)

Adrian Seungjin Lee
Adrian Seungjin Lee

Reputation: 1666

I would suggest the querystring query below.

(ResponseQ1:0 OR ResponseQ2:0 OR ResponseQ3:"skipped) NOT (ResponseQ1:0 AND Response Q2:0 AND ResponseQ3:"skipped")

Upvotes: 2

Related Questions