# How to store and search for same values in a field

**URL:** <https://discuss.elastic.co/t/how-to-store-and-search-for-same-values-in-a-field/228357>\
**Category:** Elasticsearch\
**Created:** [April 16, 2020, 3:38pm UTC](https://discuss.elastic.co/t/how-to-store-and-search-for-same-values-in-a-field/228357 "2020-04-16T15:38:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kent120103](https://avatars.discourse-cdn.com/v4/letter/k/ac91a4/32.png) [@kent120103](https://discuss.elastic.co/u/kent120103)\
**Post date:** [April 16, 2020, 3:38pm UTC](https://discuss.elastic.co/t/how-to-store-and-search-for-same-values-in-a-field/228357/1 "2020-04-16T15:38:22Z")

</div>

Dear Elastic community,

My index contains following documents:

```auto
{.      
    "_index": "sametokensearch",
	"_type": "_doc",
	"_id": "1",
	"found": true,
	"_source": {
		"dob": ["202", "020", "20-", "0-0", "-03", "03-", "3-0", "-03"]
	}
}

```

```auto
{.      
    "_index": "sametokensearch",
	"_type": "_doc",
	"_id": "2",
	"found": true,
	"_source": {
		"dob": ["202", "020", "20-", "0-0", "-03", "03-", "3-0", "-04"]
	}
}

```

```auto
{.      
    "_index": "sametokensearch",
	"_type": "_doc",
	"_id": "3",
	"found": true,
	"_source": {
		"dob": ["202", "020", "20-", "0-0", "-03", "03-", "3-0", "-05"]
	}
}

```

There are three documents. Each document only has one field - "dob". This field is an array of "text" values. Its mapping is

```auto
{
    "sametokensearch": {
        "mappings": {
            "properties": {
                "dob": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }
            }
        }
    }
}

```

Elasticsearch release = 7.5.0

Then I search for documents as `/sametokensearch/doc/_search?size=50`

```auto
{
    "query": {
        "query_string": {
        	"query": "dob: (202 AND 020 AND 20- AND 0-0 AND \\-03 AND 03- AND 3-0 AND \\-03)"
        }
    }
}

```

Result is all of the **three** documents.

But if I search for `"dob: (202 AND 020 AND 20- AND 0-0 AND \\-03 AND 03- AND 3-0 AND \\-04)"`, result is the document of id = 2.

My first search query contains the same "text" value - "-03" twice. To me, it seems like the multiple occurs of "-03" token have been treated as single occur during search.

What I would like to achieve is

1. Searching for **dob: (202 AND 020 AND 20- AND 0-0 AND \-03 AND 03- AND 3-0 AND \-03)**, returns only the document of id = 1. It is more like a precisely match.
2. Searching for **dob: (202 AND 020 AND 20- AND 0-0 AND \-03 AND 03- AND 3-0)**, returns all the 3 documents. Because this field contains **8** values in all **3** document, but I only search for **7** of them.
3. The order of tokens is also considered. Since all of the 3 documents start with "202, 020". If I search for **dob: (020 AND 202)**, there should be no match.

Is it possible to change my search query without changing my index?

---

<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:** [May 14, 2020, 3:38pm UTC](https://discuss.elastic.co/t/how-to-store-and-search-for-same-values-in-a-field/228357/2 "2020-05-14T15:38:22Z")

</div>

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