Terms Query Doesn't work on keywords

(Santhosh) #1

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?

(David Pilato) #2

It's because you defined a mapping for riskApplicabilityAttributes.Locale but indexed a field named Locale.

(system) closed #3

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