# Querying All Text/Keyword Fields, Including Nested Fields

**URL:** <https://discuss.elastic.co/t/querying-all-text-keyword-fields-including-nested-fields/370720>\
**Category:** Elasticsearch\
**Created:** [November 18, 2024, 9:14pm UTC](https://discuss.elastic.co/t/querying-all-text-keyword-fields-including-nested-fields/370720 "2024-11-18T21:14:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jalex](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@jalex](https://discuss.elastic.co/u/jalex)\
**Post date:** [November 18, 2024, 9:14pm UTC](https://discuss.elastic.co/t/querying-all-text-keyword-fields-including-nested-fields/370720/1 "2024-11-18T21:14:03Z")

</div>

Hello,

I am looking for a way to search across all text and keyword fields, including nested fields, in an index for keyword matches and then retrieve which field it hit on. I don’t necessarily know which field the keyword might hit on because the data is very complex and heavily nested. Because of that, I don’t want to be restricted to a list of fields that I think I might want to search on, but I do need to report back which field the query hit on.

I have tried query\_string queries with no field set, but this doesn’t work on nested documents. I tried multi-match query with fields: empty list, but it also didn’t work with the nested fields. I’m wondering if anyone has suggestions on how to accomplish this. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![jessgarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessgarson/32/129841_2.png) [@jessgarson](https://discuss.elastic.co/u/jessgarson)\
**Post date:** [November 18, 2024, 11:34pm UTC](https://discuss.elastic.co/t/querying-all-text-keyword-fields-including-nested-fields/370720/2 "2024-11-18T23:34:07Z")

</div>

Thanks for reaching out, @jalex. Do you have example of the multi-match queries you were working on?

---

<div class="post-metadata">

**Author:** ![jalex](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@jalex](https://discuss.elastic.co/u/jalex)\
**Post date:** [November 19, 2024, 5:44pm UTC](https://discuss.elastic.co/t/querying-all-text-keyword-fields-including-nested-fields/370720/3 "2024-11-19T17:44:31Z")

</div>

Hi @jessgarson

The query I used was along these lines:

```auto
{“query”: {
    “multi_match”: {
        “query”: “something”,
        “fields”: []
    }
}}

```

It did find matches on regular (non-nested) text fields, but it did not find matches on nested text fields that I would have wanted it to.

---

<div class="post-metadata">

**Author:** ![jessgarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessgarson/32/129841_2.png) [@jessgarson](https://discuss.elastic.co/u/jessgarson)\
**Post date:** [November 19, 2024, 10:05pm UTC](https://discuss.elastic.co/t/querying-all-text-keyword-fields-including-nested-fields/370720/4 "2024-11-19T22:05:28Z")

</div>

Thanks for following up, @jalex.

Have you tried anything like this yet:

```auto
{
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "query": "your_search_term",
            "fields": ["field1", "field2", "field3"]
          }
        },
        {
          "nested": {
            "path": "nestedField",
            "query": {
              "query_string": {
                "query": "your_search_term",
                "fields": ["nestedField.subfield1", "nestedField.subfield2"]
              }
            },
            "inner_hits": {} 
          }
        }
      ]
    }
  },
  "_source": ["field1", "field2", "field3", "nestedField.subfield1", "nestedField.subfield2"],
  "highlight": {
    "fields": {
      "*": {}
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![jalex](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@jalex](https://discuss.elastic.co/u/jalex)\
**Post date:** [November 22, 2024, 2:40pm UTC](https://discuss.elastic.co/t/querying-all-text-keyword-fields-including-nested-fields/370720/5 "2024-11-22T14:40:16Z")

</div>

Hi, @jessgarson  
I think I can make this work. Thank you for your help!

---

<div class="post-metadata">

**Author:** ![jessgarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessgarson/32/129841_2.png) [@jessgarson](https://discuss.elastic.co/u/jessgarson)\
**Post date:** [November 22, 2024, 3:19pm UTC](https://discuss.elastic.co/t/querying-all-text-keyword-fields-including-nested-fields/370720/6 "2024-11-22T15:19:01Z")

</div>

Thanks, @jalex. Let me know if you need any further help here or you have any questions.
