# Query returns empty result when filtering on labels and timestamp

**URL:** <https://discuss.elastic.co/t/query-returns-empty-result-when-filtering-on-labels-and-timestamp/311305>\
**Category:** Elasticsearch\
**Created:** [August 3, 2022, 12:21pm UTC](https://discuss.elastic.co/t/query-returns-empty-result-when-filtering-on-labels-and-timestamp/311305 "2022-08-03T12:21:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ithline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ithline/32/109197_2.png) [@ithline](https://discuss.elastic.co/u/ithline)\
**Post date:** [August 3, 2022, 12:21pm UTC](https://discuss.elastic.co/t/query-returns-empty-result-when-filtering-on-labels-and-timestamp/311305/1 "2022-08-03T12:21:28Z")

</div>

Hello there,  
I'm having some problems with querying in Kibana, so I tried to create manual query using the /\_search API.

My index template is composed of `.alerts-ecs-mappings`, `logs-mappings` and `logs-settings` component templates.

Running a query like below returns an empty result.

```auto
{
  "query": {
    "bool": {
      "must": [],
      "filter": [
        {
          "range": {
            "@timestamp": {
              "format": "strict_date_optional_time",
              "gte": "2022-08-03T00:00:00.000Z",
              "lte": "2022-08-05T11:04:27.086Z"
            }
          }
        },
        {
          "match":{
            "labels.job_type": "repair"
          }
        }
      ],
      "should": [],
      "must_not": []
    }
  }
}

```

But removing either the `range` or `match` parts returns expected results. If I add some other filters on ECS fields, eg. `log.level` or `event.action`, then I get results, but as soon as I combine any `labels.*` and `@timestamp`, then result is empty.

I'm getting pretty desperate, because we use elastic and kibana to store logs and this means, that basically I cannot do any filters on our logs.

Any tips what could cause this behaviour?

---

<div class="post-metadata">

**Author:** ![Ofir\_Edi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ofir_edi/32/78181_2.png) [@Ofir\_Edi](https://discuss.elastic.co/u/Ofir_Edi)\
**Post date:** [August 3, 2022, 1:20pm UTC](https://discuss.elastic.co/t/query-returns-empty-result-when-filtering-on-labels-and-timestamp/311305/2 "2022-08-03T13:20:41Z")

</div>

Hi @ithline ,  
Can you please share a document that should match your criteria?  
Also kindly sure the mapping of the index/indices you are trying to query

---

<div class="post-metadata">

**Author:** ![ithline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ithline/32/109197_2.png) [@ithline](https://discuss.elastic.co/u/ithline)\
**Post date:** [August 4, 2022, 7:30am UTC](https://discuss.elastic.co/t/query-returns-empty-result-when-filtering-on-labels-and-timestamp/311305/3 "2022-08-04T07:30:32Z")

</div>

After some more diagnostics, it looks like at some point the `labels` field stopped being indexed, because I can filter older documents by that field, but I cannot get any new ones.

Then I double checked settings on older indices and the newer ones and it turns out that `dynamic_mapping` was disabled at some point. Enabling it and rolling over data stream enables filtering on `labels` again.

---

<div class="post-metadata">

**Author:** ![Ofir\_Edi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ofir_edi/32/78181_2.png) [@Ofir\_Edi](https://discuss.elastic.co/u/Ofir_Edi)\
**Post date:** [August 4, 2022, 8:38am UTC](https://discuss.elastic.co/t/query-returns-empty-result-when-filtering-on-labels-and-timestamp/311305/4 "2022-08-04T08:38:11Z")

</div>

So at the moment the behavior is as expected (including filtering by @timestamp)?

---

<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:** [September 1, 2022, 8:38am UTC](https://discuss.elastic.co/t/query-returns-empty-result-when-filtering-on-labels-and-timestamp/311305/5 "2022-09-01T08:38:59Z")

</div>

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