I have below mapping for elastic search
{
"2021-05-ui":{
"mappings":{
"userinfo":{
"properties":{
"address":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"name":{
"type":"keyword"
},
"userId":{
"type":"keyword"
}
}
}
}
}
I want to use the term query on userId field like below its doesn't work , but when i remove .keyword from below query its work , i want the query which match exact value for userId field
{
"query": {
"bool": {
"filter": [
{
"term": {
"userId.keyword": "[email protected]"
}
}
]
}
}
}
i want the query with "userId.keyword" only since other environments its has both the text and keyword mapping , could you please suggest which query we can use to get the exact match , i tried using match,match_phrase but didnt help much.
userIdfield is ofkeywordtype, which means it uses keyword analyzer instead of the standard analyzer. In this case, you will be getting the result only for the exact matchSince
userIdis ofkeywordtype and there is no field foruserId.keyword, you have to useuserIdfor term queryHowever if you want to store
userIdfield as of bothtextandkeywordtype, then you can update your index mapping as shown below to use multi fieldsAnd then reindex the data again. After this, you will be able to query using the
"userId"field as ofkeywordtype and"userId.raw"as oftexttype