# Search multiple values for a single field

**URL:** <https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327>\
**Category:** Elasticsearch\
**Created:** [March 25, 2021, 11:21am UTC](https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327 "2021-03-25T11:21:32Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![subham\_p](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@subham\_p](https://discuss.elastic.co/u/subham_p)\
**Post date:** [March 25, 2021, 11:21am UTC](https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327/1 "2021-03-25T11:21:32Z")

</div>

Hii.. All , I am pretty new in elk search, I want to find out multiple values for a single field (diseases:” fever,covid\_19”) with in a must with wildcard condition

here the data is like this  
Diseases: “fever, headache, cold cough”  
Diseases:” fever, infection”  
Diseases:” fever,covid\_19”

I have tried like this

```auto
{ 'query': {'bool': {'filter': [{'bool': {'must': [{'wildcard': {'diseases': 'fev*'}}, {'wildcard': {'diseases': 'cov*'}}, {'range': {'visit_created_dttm': {'gte': '2020-06-23', 'lte': '2020-12-30'}}}}}

```

but it fails to recognize perticular values ..  
please help me..how can i find out the the perticular values.

---

<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:** [March 25, 2021, 11:29am UTC](https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327/2 "2021-03-25T11:29:58Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can copy and paste in Kibana dev console, click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![subham\_p](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@subham\_p](https://discuss.elastic.co/u/subham_p)\
**Post date:** [March 25, 2021, 11:34am UTC](https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327/3 "2021-03-25T11:34:14Z")

</div>

we want to find out multiple comma sepated values for a single field  
for example  
field=value1,value2  
diesease = fever,head ache

please suggest me the search query for this..

---

<div class="post-metadata">

**Author:** ![subham\_p](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@subham\_p](https://discuss.elastic.co/u/subham_p)\
**Post date:** [March 25, 2021, 11:47am UTC](https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327/4 "2021-03-25T11:47:17Z")

</div>

1.diesease = fever,body pain,head ache  
2.diesease = fever,cold cough,  
3.diesease =blood preesure, fever,stomach pain  
4.diesease =head ache, fever,stomach pain

we have to sort out those patient whose have fever and head ache both  
as the above example  
we should show only 2 records  
1.diesease = fever,body pain,head ache  
4.diesease =head ache, fever,stomach pain

please suggest me the search query for 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:** [March 25, 2021, 11:51am UTC](https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327/5 "2021-03-25T11:51:07Z")

</div>

Please provide a script we can start from.

---

<div class="post-metadata">

**Author:** ![subham\_p](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@subham\_p](https://discuss.elastic.co/u/subham_p)\
**Post date:** [March 25, 2021, 12:03pm UTC](https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327/6 "2021-03-25T12:03:42Z")

</div>

I am trying the search script like this

```auto
GET /patient_history/_search
{"query": {"bool": {"filter": [{"bool": {"must": [{"wildcard": {"diseases": "fever,head ache"}}]}}]}}}

```

---

<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:** [March 25, 2021, 1:25pm UTC](https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327/7 "2021-03-25T13:25:16Z")

</div>

When I run it it says that the index does not exist.

---

<div class="post-metadata">

**Author:** ![subham\_p](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@subham\_p](https://discuss.elastic.co/u/subham_p)\
**Post date:** [March 26, 2021, 4:44am UTC](https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327/8 "2021-03-26T04:44:27Z")

</div>

Yes.. I think you have to insert some dummy above data by creating an index.. as any name like patient\_history..  
So that you can fetch that..  
Hope you understood our requirement..

---

<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:** [March 26, 2021, 6:13am UTC](https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327/9 "2021-03-26T06:13:01Z")

</div>

But what if you share with us this dummy data?

Again, have a look at the example.

> [@dadoonet](#):
>
> Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21).

---

<div class="post-metadata">

**Author:** ![subham\_p](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@subham\_p](https://discuss.elastic.co/u/subham_p)\
**Post date:** [March 28, 2021, 3:46pm UTC](https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327/10 "2021-03-28T15:46:11Z")

</div>

```auto
hits": {
        "total": {
            "value": 4,
            "relation": "eq"
        },
        "max_score": 1.0,
        "hits": [
            {
                "_index": "patient_history",
                "_type": "_doc",
                "_id": "1",
                "_score": 1.0,
                "_source": {
                    "diesease": "fever,body pain,head ache"}, {
                "_index": "patient_history",
                "_type": "_doc",
                "_id": "2",
                "_score": 1.0,
                "_source": {
                    "diesease": "fever,cold cough"},
 {
                "_index": "patient_history",
                "_type": "_doc",
                "_id": "3",
                "_score": 1.0,
                "_source": {
                    "diesease": "blood preesure, fever,stomach pain"}, 
{
                "_index": "patient_history",
                "_type": "_doc",
                "_id": "4",
                "_score": 1.0,
                "_source": {
                    "diesease": "head ache, fever,stomach pain"}

```

1.diesease = "fever,body pain,head ache",  
2.diesease = "fever,cold cough"  
3.diesease ="blood preesure, fever,stomach pain"  
4.diesease ="head ache, fever,stomach pain"

we want to split out multiple comma sepated values for a single field and sort out those patient whose have "fever" and "head ache" both  
as the above example  
we should show only 2 records  
1.diesease = "fever,body pain,head ache"  
4.diesease ="head ache, fever,stomach pain"

---

<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:** [March 29, 2021, 1:36pm UTC](https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327/11 "2021-03-29T13:36:31Z")

</div>

We are getting closer. Very cool.

Just to be sure that you understand what is expected, I'm going to copy and paste what a typical script is so you can copy/paste it your self and see how this can work. Note that this is coming from this post: [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21)

```auto
DELETE index
PUT index/_doc/1
{
  "foo": "bar"
}
GET index/_search
{
  "query": {
    "match": {
      "foo": "bar"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![subham\_p](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@subham\_p](https://discuss.elastic.co/u/subham_p)\
**Post date:** [March 31, 2021, 9:02am UTC](https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327/12 "2021-03-31T09:02:11Z")

</div>

```auto
GET /patient_history/_search
{"query": {"bool": {"filter": [{"bool": {"must": [{"wildcard": {"diseases": "fever,head ache"}}]}}]}}}

```

Sorry, I am not getting the appropriate solution, please check the above details that I have asked.

Hope you will understand..

---

<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:** [March 31, 2021, 11:52am UTC](https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327/13 "2021-03-31T11:52:42Z")

</div>

When I run it it says that the index does not exist.

---

<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:** [April 28, 2021, 11:53am UTC](https://discuss.elastic.co/t/search-multiple-values-for-a-single-field/268327/14 "2021-04-28T11:53:28Z")

</div>

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