# Filtering by a nested common field

**URL:** <https://discuss.elastic.co/t/filtering-by-a-nested-common-field/359856>\
**Category:** Elasticsearch\
**Created:** [May 20, 2024, 4:29pm UTC](https://discuss.elastic.co/t/filtering-by-a-nested-common-field/359856 "2024-05-20T16:29:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabio\_Bazurto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fabio_bazurto/32/134661_2.png) [@Fabio\_Bazurto](https://discuss.elastic.co/u/Fabio_Bazurto)\
**Post date:** [May 20, 2024, 4:29pm UTC](https://discuss.elastic.co/t/filtering-by-a-nested-common-field/359856/1 "2024-05-20T16:29:49Z")

</div>

Given I have records with following structure:

```auto
{ ... ,
  "CustomerInfo": {
      "GasStation": {
          "cardID": "abc123456"
       }
   }
}

```

```auto

{ ... ,
  "CustomerInfo": {
      "SuperMarket": {
          "cardID": "abc123456"
       }
   }
}

```

```auto

{ ... ,
  "CustomerInfo": {
      "School": {
          "cardID": "dfg789456"
       }
   }
}

```

Currently I'm using this

```auto
{
  "query": {
    "bool": {
      "should": [
        {
            "CustomerInfo.GasStation.cardID": "*12345*"
        },
        {
            "CustomerInfo.SuperMarket.cardID": "*12345*"
        },
        {
            "CustomerInfo.Schools.cardID": "*12345*"
        }
      ],
      "minimum_should_match": 1
    }
  }
}

```

Is it possible to filter by cardID only?  
Do we have a matcher to find using something like `"CustomerInfo.*.cardID"`?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [May 21, 2024, 7:44pm UTC](https://discuss.elastic.co/t/filtering-by-a-nested-common-field/359856/2 "2024-05-21T19:44:18Z")

</div>

Hi @Fabio_Bazurto

I think with [query\_string](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-multi-field) should works:

```auto
{
  "query": {
    "query_string": {
      "fields": [
        "CustomerInfo.*.cardID"
      ],
      "query": "*123456*"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Fabio\_Bazurto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fabio_bazurto/32/134661_2.png) [@Fabio\_Bazurto](https://discuss.elastic.co/u/Fabio_Bazurto)\
**Post date:** [May 21, 2024, 9:20pm UTC](https://discuss.elastic.co/t/filtering-by-a-nested-common-field/359856/3 "2024-05-21T21:20:36Z")

</div>

My previous approach was simple\_query\_string but this is much better.  
Thank you. It works like a charm.
