# Wildcard inside nested query and a value match

**URL:** <https://discuss.elastic.co/t/wildcard-inside-nested-query-and-a-value-match/161551>\
**Category:** Elasticsearch\
**Created:** [December 19, 2018, 4:17pm UTC](https://discuss.elastic.co/t/wildcard-inside-nested-query-and-a-value-match/161551 "2018-12-19T16:17:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nedko\_Georgiev](https://avatars.discourse-cdn.com/v4/letter/n/b782af/32.png) [@Nedko\_Georgiev](https://discuss.elastic.co/u/Nedko_Georgiev)\
**Post date:** [December 19, 2018, 4:17pm UTC](https://discuss.elastic.co/t/wildcard-inside-nested-query-and-a-value-match/161551/1 "2018-12-19T16:17:59Z")

</div>

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

```auto
{
  "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:

```auto
{
  "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.

---

<div class="post-metadata">

**Author:** ![Nedko\_Georgiev](https://avatars.discourse-cdn.com/v4/letter/n/b782af/32.png) [@Nedko\_Georgiev](https://discuss.elastic.co/u/Nedko_Georgiev)\
**Post date:** [December 20, 2018, 12:43pm UTC](https://discuss.elastic.co/t/wildcard-inside-nested-query-and-a-value-match/161551/2 "2018-12-20T12:43:06Z")

</div>

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

```auto
{
  "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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 17, 2019, 12:43pm UTC](https://discuss.elastic.co/t/wildcard-inside-nested-query-and-a-value-match/161551/3 "2019-01-17T12:43:15Z")

</div>

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