M_M
M_M

Reputation: 79

How to perform MINUS operation in elasticsearch

I'm trying to create a MINUS query like Mysql (DATASET1-DATASET2) in elasticsearch using queryDSL but can't find a way.

Anyone could show me the way? Tx in advance

Upvotes: 0

Views: 1234

Answers (1)

baudsp
baudsp

Reputation: 4110

You can use the bool query with must and must not.
Documentation on the bool query

You would put the query for DATASET1 in the must and the query for DATASET2 in must_not:

{
"bool" : {
    "must" : {
        DATASET1
    }
    "must_not" : {
        DATASET2
    }
}

}

For example:

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": {
            "range": {
              "@timestamp": {
                "lte": 1467811620000,
                "gte": 1467811520000
              }
            }
          },
          "must_not": {
            "term": {
              "_type": "bus-api"
            }
          }
        }
      }
    }
  }
}

This would return all the documents between those two times, excluding those of type bus-api.

Upvotes: 1

Related Questions