Wildcard inside nested query and a value match

I'm trying to migrate from ES 0.90 to 6.5 and I have the following query:

{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "field Value",
            "fields": "fieldName"
          }
        },
        {
          "multi_match": {
            "query": "yes",
            "fields": "property.ACTIVE_*"
          }
        },
        {
          "multi_match": {
            "query": "true",
            "fields": "property.ACTIVE_*"
          }
        }
      ]
    }
  },
  "filter": {
    "term": {
      "type": "documentType"
    }
  }
}

How can I rewrite this in ES6.5?
I've tried something like this:

{
  "query": {
    "bool": {
      "filter": [
        {
          "nested": {
            "path": "properties",
            "query": {
              "bool": {
                "should": [
                  {
                    "wildcard": {
                      "properties.key.keyword": "ACTIVE_*"
                    }
                  },
                  {
                    "match": {
                      "properties.value": "true"
                    }
                  },
                  {
                    "match": {
                      "properties.value": "Yes"
                    }
                  },
                  {
                    "match": {
                      "properties.value": "fieldValue"
                    }
                  },
                  {
                    "match": {
                      "properties.key": "fieldValueName"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

But how can I link the two properties value "Yes" and "true" to be checked with the wildcard "ACTIVE_*" and the other properties.value "fieldValue" together with the remaining "fieldValueName". So if any document matches the wildcard field, which is a nested data and the same object has a value field with "Yes" or "true" to be returned. Or if the document has a nested data with "value" field of "fieldValue" and "key" field of "fieldValueName" to be returned as well. I didn't include the filter term of "documentType", but I guess I'll add this after I figure out the rest of the query.

Just for the record, here's the solution or at least one of them:

{
  "query": {
    "bool": {
      "filter": [
        {
          "nested": {
            "path": "properties",
            "query": {
              "bool": {
                "should": [
                  {
                    "bool": {
                      "must": [
                        {
                          "wildcard": {
                            "properties.key.keyword": "ACTIVE_*"
                          }
                        },
                        {
                          "match": {
                            "properties.value": "true"
                          }
                        }
                      ]
                    }
                  },
                  {
                    "bool": {
                      "must": [
                        {
                          "wildcard": {
                            "properties.key.keyword": "ACTIVE_*"
                          }
                        },
                        {
                          "match": {
                            "properties.value": "Yes"
                          }
                        }
                      ]
                    }
                  },
                  {
                    "bool": {
                      "must": [
                        {
                          "match": {
                            "properties.value": "field Value"
                          }
                        },
                        {
                          "match": {
                            "properties.key": "fieldName"
                          }
                        }
                      ]
                    }
                  }
                ]
              }
            }
          }
        },
        {
          "term": {
            "type.keyword": "documentType"
          }
        }
      ]
    }
  }
}

It did help me asking you, so it wasn't a waste. If somebody finds a better way, please let me know.

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