Query with union and subtract by field

Hi. I'm new in elasticsearch, need some help to write a query.
Assume this is my index data:

    "_source" : {
      "id" : "1",
      "tag" : "tag1"
    }
    "_source" : {
      "id" : "2",
      "tag" : "tag1"
    }
    "_source" : {
      "id" : "2",
      "tag" : "tag2"
    }
    "_source" : {
      "id" : "3",
      "tag" : "tag2"
    }
    "_source" : {
      "id" : "1",
      "tag" : "tag3"
    }
    "_source" : {
      "id" : "4",
      "tag" : "tag4"
    }

I want a query return docs with unique id of {"tag1", "tag2"}-{"tag3", "tag4"} where the subtract is by field id. As a result:

    "_source" : {
      "id" : "2",
      "tag" : "tag1"
    }
    "_source" : {
      "id" : "3",
      "tag" : "tag2"
    }

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