Match query not returning results

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:

{ 
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?


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

Why do i get 0 results?

Thanks in advance!

Welcome!

What's the mapping?

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:

{
    "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):

{
  "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"
          }
        }
      }
    }
  }
}

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

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

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.

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!

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