# How to add searched value with terms query results

**URL:** <https://discuss.elastic.co/t/how-to-add-searched-value-with-terms-query-results/324174>\
**Category:** Elasticsearch\
**Created:** [January 29, 2023, 11:23am UTC](https://discuss.elastic.co/t/how-to-add-searched-value-with-terms-query-results/324174 "2023-01-29T11:23:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nowrin\_Hossain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nowrin_hossain/32/99918_2.png) [@Nowrin\_Hossain](https://discuss.elastic.co/u/Nowrin_Hossain)\
**Post date:** [January 29, 2023, 11:23am UTC](https://discuss.elastic.co/t/how-to-add-searched-value-with-terms-query-results/324174/1 "2023-01-29T11:23:39Z")

</div>

Hello,

I want to do search an index with multiple values. I want to also know which search result comes for which searched value. Can I do this in case of terms query.  
e.g.

```auto
GET /_search
{
  "query": {
    "terms": {
      "user.id": ["kimchy", "elkbee"],
      "boost": 1.0
    }
  }
}

```

expected output (including for\_searched\_value):

```auto
{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": 1,
        "hits": [
            {
                "_index": "teachers",
                "_type": "_doc",
                "_id": "f3822b08-27c4-485a-adce-cec2af1b19b4",
                "_score": 1,
                "_source": {
                    "user": {
                        "id": "kimchy"
                    },
                    "subject": "English"
                },
                "for_searched_value": "kimchy"
            },
            {
                "_index": "teachers",
                "_type": "_doc",
                "_id": "f3822b08-27c4-485a-adce-cec2af1b19b4",
                "_score": 1,
                "_source": {
                    "user": {
                        "id": "kimchy"
                    },
                    "subject": "Physics"
                },
                "for_searched_value": "kimchy"
            },
            {
                "_index": "teachers",
                "_type": "_doc",
                "_id": "f3822b08-27c4-485a-adce-cec2af1b19b4",
                "_score": 1,
                "_source": {
                    "user": {
                        "id": "elkbee"
                    },
                    "subject": "Math"
                },
                "for_searched_value": "elkbee"
            }
            
        ]
    }
}

```

Is there any way to know similar information like matched value for every search hit from code. I am using flask for my application.

---

<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:** [February 26, 2023, 11:24am UTC](https://discuss.elastic.co/t/how-to-add-searched-value-with-terms-query-results/324174/2 "2023-02-26T11:24:15Z")

</div>

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