I am using a simple mapping with analyzers like below:
PUT /risks_keyword/
{
"mappings": {
"_doc": {
"properties": {
"riskApplicabilityAttributes": {
"properties": {
"Locale": {
"type": "keyword"
}
}
}
}
}
},"settings": {
"index": {
"analysis": {
"filter" : {
"risk_filter" : {
"type" : "pattern_capture",
"generate_word_parts": false,
"preserve_original" : true,
"patterns" : []
}
},
"analyzer": {
"risk_analyzer": {
"tokenizer": "keyword",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
}
}
}
Then, I indexed a doc:
POST /risks_keyword/_doc/2?refresh
{
"Locale": [
"en-US",
"en-GB",
"ja-JP"
],
"Id": "Risk_2"
}
Now I am using a Terms query to search for docs that have particulat locale:
GET /risks_keyword/_search
{
"query": {
"terms": {
"Locale": [
"en-US"
]
}
}
}
But this returns 0 docs. Below 2 queries return the doc:
GET /risks_keyword/_search
{
"query": {
"terms": {
"Locale": [
"en"
]
}
}
}
and
GET /risks_keyword/_search
{
"query": {
"terms": {
"Locale": [
"us"
]
}
}
}
Ofcourse, the match query works fine but how do I make it work using the Terms query?