Dear Elastic community,
My index contains following documents:
{.
"_index": "sametokensearch",
"_type": "_doc",
"_id": "1",
"found": true,
"_source": {
"dob": ["202", "020", "20-", "0-0", "-03", "03-", "3-0", "-03"]
}
}
{.
"_index": "sametokensearch",
"_type": "_doc",
"_id": "2",
"found": true,
"_source": {
"dob": ["202", "020", "20-", "0-0", "-03", "03-", "3-0", "-04"]
}
}
{.
"_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
{
"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
{
"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
- 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.
- 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.
- 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?