# Match query not returning results

**URL:** <https://discuss.elastic.co/t/match-query-not-returning-results/337815>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [July 6, 2023, 3:25pm UTC](https://discuss.elastic.co/t/match-query-not-returning-results/337815 "2023-07-06T15:25:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![senadk](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@senadk](https://discuss.elastic.co/u/senadk)\
**Post date:** [July 6, 2023, 3:25pm UTC](https://discuss.elastic.co/t/match-query-not-returning-results/337815/1 "2023-07-06T15:25:59Z")

</div>

Hi everyone,

I started today with Elastic Search and have been working on some endpoints to get and post data.  
I do get a problem when trying to get results back on a `match` query.

This is my document:

```auto
{ 
exception: [
  {
    "name": "test null",
    "type": "test type null",
    "sequence": 1,
    "message": "test message null",
    "stacktrace": "test stacktrace null",
    "customer": 1,
    "createdate": "2023-07-03T14:55:14.0535593+02:00"
  },
  {
    "name": "test2 null",
    "type": "test2 2type ",
    "sequence": 2,
    "message": "test2 message null",
    "stacktrace": "test2 stacktrace null",
    "customer": 2,
    "createdate": "2023-07-03T14:55:14.0535593+02:00"
  }
],
customerName: "test"
}

```

This is my query and URL:

https:/ /test./search-exceptions/\_search?

```auto

{
  "query": {
    "match": {
      "type": {
          "query": "test2 2type",
          "operator": "AND"
      }
    }
  }
}

```

Why do i get 0 results?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 6, 2023, 4:54pm UTC](https://discuss.elastic.co/t/match-query-not-returning-results/337815/2 "2023-07-06T16:54:43Z")

</div>

Welcome!

What's the mapping?

---

<div class="post-metadata">

**Author:** ![senadk](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@senadk](https://discuss.elastic.co/u/senadk)\
**Post date:** [July 6, 2023, 9:29pm UTC](https://discuss.elastic.co/t/match-query-not-returning-results/337815/3 "2023-07-06T21:29:26Z")

</div>

Thank you Dadoonet!  
I knew I forgot something.

I find it weird that in the mapping `exceptionlog` doesn't have anything like `type: nested` because its an array with objects like this:

```auto
{
    "name": "test2 null",
    "type": "test2 2type ",
    "sequence": 2,
    "message": "test2 message null",
    "stacktrace": "test2 stacktrace null",
    "customer": 2,
    "createdate": "2023-07-03T14:55:14.0535593+02:00"
  }

```

Here is my mapping (the mapping was added auto by the `_bulk` endpoint when i sent my first data to the index):

```auto
{
  "mappings": {
    "dynamic": "true",
    "dynamic_templates": [
      {
        "all_text_fields": {
          "match_mapping_type": "string",
          "mapping": {
            "analyzer": "iq_text_base",
            "fields": {
              "delimiter": {
                "analyzer": "iq_text_delimiter",
                "type": "text",
                "index_options": "freqs"
              },
              "joined": {
                "search_analyzer": "q_text_bigram",
                "analyzer": "i_text_bigram",
                "type": "text",
                "index_options": "freqs"
              },
              "prefix": {
                "search_analyzer": "q_prefix",
                "analyzer": "i_prefix",
                "type": "text",
                "index_options": "docs"
              },
              "enum": {
                "ignore_above": 2048,
                "type": "keyword"
              },
              "stem": {
                "analyzer": "iq_text_stem",
                "type": "text"
              }
            }
          }
        }
      }
    ],
    "properties": {
      "customerstage": {
        "type": "text",
        "fields": {
          "delimiter": {
            "type": "text",
            "index_options": "freqs",
            "analyzer": "iq_text_delimiter"
          },
          "enum": {
            "type": "keyword",
            "ignore_above": 2048
          },
          "joined": {
            "type": "text",
            "index_options": "freqs",
            "analyzer": "i_text_bigram",
            "search_analyzer": "q_text_bigram"
          },
          "prefix": {
            "type": "text",
            "index_options": "docs",
            "analyzer": "i_prefix",
            "search_analyzer": "q_prefix"
          },
          "stem": {
            "type": "text",
            "analyzer": "iq_text_stem"
          }
        },
        "analyzer": "iq_text_base"
      },
      "exceptionlog": {
        "properties": {
          "createDate": {
            "type": "date"
          },
          "createdate": {
            "type": "date"
          },
          "customerstagekey": {
            "type": "text",
            "fields": {
              "delimiter": {
                "type": "text",
                "index_options": "freqs",
                "analyzer": "iq_text_delimiter"
              },
              "enum": {
                "type": "keyword",
                "ignore_above": 2048
              },
              "joined": {
                "type": "text",
                "index_options": "freqs",
                "analyzer": "i_text_bigram",
                "search_analyzer": "q_text_bigram"
              },
              "prefix": {
                "type": "text",
                "index_options": "docs",
                "analyzer": "i_prefix",
                "search_analyzer": "q_prefix"
              },
              "stem": {
                "type": "text",
                "analyzer": "iq_text_stem"
              }
            },
            "analyzer": "iq_text_base"
          },
          "name": {
            "type": "text",
            "fields": {
              "delimiter": {
                "type": "text",
                "index_options": "freqs",
                "analyzer": "iq_text_delimiter"
              },
              "enum": {
                "type": "keyword",
                "ignore_above": 2048
              },
              "joined": {
                "type": "text",
                "index_options": "freqs",
                "analyzer": "i_text_bigram",
                "search_analyzer": "q_text_bigram"
              },
              "prefix": {
                "type": "text",
                "index_options": "docs",
                "analyzer": "i_prefix",
                "search_analyzer": "q_prefix"
              },
              "stem": {
                "type": "text",
                "analyzer": "iq_text_stem"
              }
            },
            "analyzer": "iq_text_base"
          },
          "message": {
            "type": "text",
            "fields": {
              "delimiter": {
                "type": "text",
                "index_options": "freqs",
                "analyzer": "iq_text_delimiter"
              },
              "enum": {
                "type": "keyword",
                "ignore_above": 2048
              },
              "joined": {
                "type": "text",
                "index_options": "freqs",
                "analyzer": "i_text_bigram",
                "search_analyzer": "q_text_bigram"
              },
              "prefix": {
                "type": "text",
                "index_options": "docs",
                "analyzer": "i_prefix",
                "search_analyzer": "q_prefix"
              },
              "stem": {
                "type": "text",
                "analyzer": "iq_text_stem"
              }
            },
            "analyzer": "iq_text_base"
          },
          "sequence": {
            "type": "long"
          },
          "stacktrace": {
            "type": "text",
            "fields": {
              "delimiter": {
                "type": "text",
                "index_options": "freqs",
                "analyzer": "iq_text_delimiter"
              },
              "enum": {
                "type": "keyword",
                "ignore_above": 2048
              },
              "joined": {
                "type": "text",
                "index_options": "freqs",
                "analyzer": "i_text_bigram",
                "search_analyzer": "q_text_bigram"
              },
              "prefix": {
                "type": "text",
                "index_options": "docs",
                "analyzer": "i_prefix",
                "search_analyzer": "q_prefix"
              },
              "stem": {
                "type": "text",
                "analyzer": "iq_text_stem"
              }
            },
            "analyzer": "iq_text_base"
          },
          "type": {
            "type": "text",
            "fields": {
              "delimiter": {
                "type": "text",
                "index_options": "freqs",
                "analyzer": "iq_text_delimiter"
              },
              "enum": {
                "type": "keyword",
                "ignore_above": 2048
              },
              "joined": {
                "type": "text",
                "index_options": "freqs",
                "analyzer": "i_text_bigram",
                "search_analyzer": "q_text_bigram"
              },
              "prefix": {
                "type": "text",
                "index_options": "docs",
                "analyzer": "i_prefix",
                "search_analyzer": "q_prefix"
              },
              "stem": {
                "type": "text",
                "analyzer": "iq_text_stem"
              }
            },
            "analyzer": "iq_text_base"
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 24, 2023, 6:36am UTC](https://discuss.elastic.co/t/match-query-not-returning-results/337815/4 "2023-07-24T06:36:52Z")

</div>

> [@senadk](#):
>
> I find it weird that in the mapping `exceptionlog` doesn't have anything like `type: nested` because its an array with objects like this:

May be. But what is generating the data/the mapping?

---

<div class="post-metadata">

**Author:** ![senadk](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@senadk](https://discuss.elastic.co/u/senadk)\
**Post date:** [July 24, 2023, 4:05pm UTC](https://discuss.elastic.co/t/match-query-not-returning-results/337815/5 "2023-07-24T16:05:27Z")

</div>

Thanks for replying, the mapping was added auto by the `_bulk` endpoint when i sent my first data to the index.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 24, 2023, 4:41pm UTC](https://discuss.elastic.co/t/match-query-not-returning-results/337815/6 "2023-07-24T16:41:43Z")

</div>

So Elasticsearch can not guess if you want to flatten the inner documents or use a nested structure, meaning more Lucene documents under the hood.

You need to create the mapping before indexing the first document and that's anyway a best practice. You can use an index template for that as well.

---

<div class="post-metadata">

**Author:** ![senadk](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@senadk](https://discuss.elastic.co/u/senadk)\
**Post date:** [July 24, 2023, 5:14pm UTC](https://discuss.elastic.co/t/match-query-not-returning-results/337815/7 "2023-07-24T17:14:06Z")

</div>

Thanks @dadoonet.

I found oud indeed that its better to create the indexing before my first document. I thought it would be nice ( and easy) if it can met auto generated by elastic self. I put your answer as solution as it would be the solution for my problem. Thanks!

---

<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:** [August 21, 2023, 5:14pm UTC](https://discuss.elastic.co/t/match-query-not-returning-results/337815/8 "2023-08-21T17:14:53Z")

</div>

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