Reputation: 5133
I am using ES 6.5 and I have the following documents
{"id": 1, "type": "a"}
{"id": 2, "type": "a b"}
Type mapping looks like this
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
Desired behavior:
a
I would like to get only the document with id 1
a b
I would like to get only the document with id 2
What I have tried:
a
then I get both 1
and 2
; if input=a b
then I get only 2
I probably tried various other solutions suggested on stackoverflow but so far nothing worked as expected. Also please note the version of ES, in newer versions we have other options.
Upvotes: 0
Views: 205
Reputation: 16172
You need to add .keyword to the type field. This uses the keyword analyzer instead of the standard analyzer (notice the ".keyword" after type field). Try out this below query -
{
"query":{
"match":{
"type.keyword":"a b"
}
}
}
Search Result:
"hits": [
{
"_index": "65327197",
"_type": "_doc",
"_id": "2",
"_score": 0.6931471,
"_source": {
"id": 2,
"type": "a b"
}
}
]
Upvotes: 1