# Array in Response

**URL:** <https://discuss.elastic.co/t/array-in-response/353334>\
**Category:** Elasticsearch\
**Created:** [February 15, 2024, 6:55am UTC](https://discuss.elastic.co/t/array-in-response/353334 "2024-02-15T06:55:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shreya\_Chandak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shreya_chandak/32/131769_2.png) [@Shreya\_Chandak](https://discuss.elastic.co/u/Shreya_Chandak)\
**Post date:** [February 15, 2024, 6:55am UTC](https://discuss.elastic.co/t/array-in-response/353334/1 "2024-02-15T06:55:58Z")

</div>

Hello Community ,  
I am new to querying elastic , there is a requirement -\> I have logs on elk with field names request(string) and average response time (Number) , I want to first specify a date\_range in query and find out for all Mondays in this range and then the expected response is array of request and average\_response\_time for each monday (falling in the date range) from time 00:00:00.000 to 23:59:59.999, how can I proceed with this?

---

<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:** [February 15, 2024, 11:04am UTC](https://discuss.elastic.co/t/array-in-response/353334/2 "2024-02-15T11:04:06Z")

</div>

Welcome!

If you don't have a field like `day_of_week` in your dataset, you can't directly query it.

But you can do something like:

```auto
GET /bytes-discuss-02/_search
{
  "runtime_mappings": {
    "question.day_of_week": {
      "type": "keyword",
      "script": {
        "source": """
        emit(doc['question.date'].value.dayOfWeek.getDisplayName(TextStyle.FULL, Locale.ROOT));
        """
      }
    },
    "solution.day_of_week": {
      "type": "keyword",
      "script": {
        "source": """
        emit(doc['solution.date'].value.dayOfWeek.getDisplayName(TextStyle.FULL, Locale.ROOT));
        """
      }
    }
  },
  "fields": [
    "title",
    "question.author.username",
    "solution.author.username",
    "question.day_of_week",
    "solution.day_of_week"
  ],
  "query": {
    "multi_match": {
      "analyzer": "whitespace",
      "query": "Monday",
      "fields": [
        "*.day_of_week"
      ]
    }
  }, 
  "_source": false
}

```

You can see a full demo here:

[![](https://us1.discourse-cdn.com/elastic/original/3X/8/f/8fb84e0caace5fa2473f42b31daca8c6ac19a24c.jpeg "Runtime fields - Daily Elastic Byte S05E04") ](https://www.youtube.com/watch?v=HpjxfS5rrhI)

The script:

> **[GitHub - dadoonet/s0504-runtime-fields: Demo scripts used for Elastic Daily...](https://github.com/dadoonet/s0504-runtime-fields)**
>
> Demo scripts used for Elastic Daily Bytes S05 - Runtime fields - dadoonet/s0504-runtime-fields

---

<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:** [March 14, 2024, 11:04am UTC](https://discuss.elastic.co/t/array-in-response/353334/3 "2024-03-14T11:04:53Z")

</div>

Closed on March 14, 2024, 11:04am UTC

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