# Search query not returning result data

**URL:** <https://discuss.elastic.co/t/search-query-not-returning-result-data/309488>\
**Category:** Elastic Search\
**Created:** [July 13, 2022, 6:54am UTC](https://discuss.elastic.co/t/search-query-not-returning-result-data/309488 "2022-07-13T06:54:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsr/32/108233_2.png) [@jsr](https://discuss.elastic.co/u/jsr)\
**Post date:** [July 13, 2022, 6:54am UTC](https://discuss.elastic.co/t/search-query-not-returning-result-data/309488/1 "2022-07-13T06:54:57Z")

</div>

I tried to fetch data via search query api through postman  
`/_search`

if I search through without filter

```auto
{
  "query": {
    "match": {
      "message": {
        "query": "matching_data"
      }
    }
  }
}

```

I'm getting data result in this query

but below query format and filter I'm not getting data

```auto
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "message": {
                "query": "matching_data"
             }
          }
        },
        {
          "range": {
            "startTime": {
              "from": "2020-01-01",
              "to": "2022-10-20"
            }
          }
        }
      ]
    }
  }
}

```

response

```auto
{
    "took": 17,
    "timed_out": false,
    "_shards": {
        "total": 381,
        "successful": 381,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 0,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    }
}

```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 13, 2022, 7:01am UTC](https://discuss.elastic.co/t/search-query-not-returning-result-data/309488/2 "2022-07-13T07:01:57Z")

</div>

Which version of Elasticsearch are you using?

What is the mapping for the fields used in the queries?

Can you provide an example document that you expect to find?

---

<div class="post-metadata">

**Author:** ![jsr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsr/32/108233_2.png) [@jsr](https://discuss.elastic.co/u/jsr)\
**Post date:** [July 13, 2022, 7:09am UTC](https://discuss.elastic.co/t/search-query-not-returning-result-data/309488/3 "2022-07-13T07:09:23Z")

</div>

> [@Christian\_Dahlqvist](#):
>
> Elasticsearch

Elasticsearch version : 7.15.2

mapping =\> "message" : "any string"

I want number of count of string match in the give time range

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 13, 2022, 8:01am UTC](https://discuss.elastic.co/t/search-query-not-returning-result-data/309488/4 "2022-07-13T08:01:14Z")

</div>

> [@jsr](#):
>
> mapping =\> "message" : "any string"

That is not the mapping. Use the [get mapping API](https://www.elastic.co/guide/en/elasticsearch/reference/8.2/indices-get-mapping.html) to get the index mappings.

Please show a sample JSON document you expect the query to find.

---

<div class="post-metadata">

**Author:** ![jsr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsr/32/108233_2.png) [@jsr](https://discuss.elastic.co/u/jsr)\
**Post date:** [July 13, 2022, 10:33am UTC](https://discuss.elastic.co/t/search-query-not-returning-result-data/309488/5 "2022-07-13T10:33:08Z")

</div>

Mapping

```auto
{
  "logs-2022.05.19" : {
    "mappings" : {
      "properties" : {
        "@timestamp" : {
          "type" : "date"
        },
        "@version" : {
          "type" : "keyword"
        },
        "appname" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "asctime" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "environment" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "exc_info" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "exc_text" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "fields" : {
          "dynamic" : "true",
          "properties" : {
            "appname" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "host" : {
              "properties" : {
                "ip" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                }
              }
            }
          }
        },
        "filename" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "funcName" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "host" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "host_ip" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "hostname" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "levelname" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "lineno" : {
          "type" : "long"
        },
        "message" : {
          "type" : "text"
        },
        "meta" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "module" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "msg" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "name" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "pathname" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "process" : {
          "type" : "long"
        },
        "processName" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "severity" : {
          "type" : "keyword"
        },
        "stack_info" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "stacktrace" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "store_id" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "thread" : {
          "type" : "long"
        },
        "threadName" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}

```

searching a string with date range

```auto
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "message": {
                "query": "matching_data"
             }
          }
        },
        {
          "range": {
            "startTime": {
              "from": "2020-01-01",
              "to": "2022-10-20"
            }
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 13, 2022, 10:38am UTC](https://discuss.elastic.co/t/search-query-not-returning-result-data/309488/6 "2022-07-13T10:38:40Z")

</div>

> [@jsr](#):
>
> ```auto
> "range": {
> "startTime": {
> "from": "2020-01-01",
> "to": "2022-10-20"
> }
> }
> 
> ```

I do not see any field named `startTime` in your mappings, which means the documents in that index does not have that field and the range query will therefore not return anything.

---

<div class="post-metadata">

**Author:** ![jsr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsr/32/108233_2.png) [@jsr](https://discuss.elastic.co/u/jsr)\
**Post date:** [July 13, 2022, 11:10am UTC](https://discuss.elastic.co/t/search-query-not-returning-result-data/309488/7 "2022-07-13T11:10:29Z")

</div>

Thanks, I have updated `startTime` with `timestamp`.  
Now I'am able to fetch the data. Help appreciated. 🎉

---

<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 10, 2022, 11:10am UTC](https://discuss.elastic.co/t/search-query-not-returning-result-data/309488/8 "2022-08-10T11:10:56Z")

</div>

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