Issue - getting multi index data based on bool filters (must_not, should)

Hi,

I have 2 indexes (Item and Product).

I'm trying to get all records from Product index and records from Item index (filtered by memberID).
But my query is not working. played with different boost values but no luck.
If I apply only 1 filter then it gets the data but not both(must_not, should) at the same time.

Basically I'm looking for an "or" operator between must_not and should.

I'm upgrading 2.x to 6.x. and I ran into this issue.

Any help is highly appreciated.

Below are the details:

Item Map:
{
"properties": {
"mbr_id": {
"type": "long"
},
"item_id": {
"type": "long"
},
"item_desc": {
"analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer",
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"prdct_id": {
"type": "long"
},
"prdct_desc": {
"analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer",
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}

Product Map:
{
"properties": {
"prdct_id": {
"type": "long"
},
"prdct_desc": {
"analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer",
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"index": "true"
}
}
}
}
}

Query:
GET search-product, search-item/_search
{
"size": 0,
"query": {
"bool": {
"filter": [
{
"bool": {
"must_not": {
"exists": {
"field": "mbr_id",
"boost": 10
}
},
"should": [
{
"terms": {
"mbr_id": [
"1258"
],
"boost": 1
}
}
],
"adjust_pure_negative": true,
"minimum_should_match": "1",
"boost": 1
}
}
]
}
}
}

To implement OR-like querying you can use the should clause of the bool query. The query that returns all products, and a subset of the items could be written like this:

GET search-product,search-item/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must_not": {
              "exists": {
                "field": "mbr_id"
              }
            }
          }
        },
        {
          "terms": {
            "mbr_id": [
              "1258"
            ]
          }
        }
      ]
    }
  }
}

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