Term query wrong behaviour?

Hi, according to the documentation a term query search for the exact match. but when I do the below search I get results


and when I look for the exact match in uppercase I dont get any results

This should not happen, or I didn't understand the documentation?

Please don't post pictures of text or code. They are difficult to read, impossible to search and replicate (if it's code), and some people may not be even able to see them :slight_smile:

It sounds like this will come down to how the field is mapped, so can you check that?

1 Like

Hi, this is the mapping of the speaker field

{
  "shakespeare" : {
    "mappings" : {
      "speaker" : {
        "full_name" : "speaker",
        "mapping" : {
          "speaker" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }
      }
    }
  }
}

It is an exact match with what is in the index, not what was in your original JSON. In your ‘text’ field the content has been lowercased.

1 Like

Your mapping does not look correct to me.

Assuming it is correct you are searching against the text field speaker not keyword fields speaker.keyword for an exact match... text field will ignore cas

Run these 1 by one below and observe the difference you will sett

PUT discuss/
{
  "mappings": {
    "properties": {
      "speaker": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    }
  }
}

POST discuss/_doc
{
  "speaker" : "DOYLE"
}

POST discuss/_doc
{
  "speaker" : "doyle"
}

GET discuss/_search
{
  "query": {
    "term": {
      "speaker": {
        "value": "doyle"
      }
    }
  }
}

GET discuss/_search
{
  "query": {
    "term": {
      "speaker.keyword": {
        "value": "doyle"
      }
    }
  }
}

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