shredding
shredding

Reputation: 5591

Keyword is tokenized and exact match does not work

I have a field named id, that looks like that:

ventures.something.123

It's mapping:

{  
   "id":{  
      "fields":{  
         "keyword":{  
            "ignore_above":256,
            "type":"keyword"
         }
      },
      "type":"text"
   }
}

My understanding is that a keyword only allows for EXACT matching - which is what I want.

However, the analyzer tells me it's tokenized:

> http http://localhost:9200/my_index/_analyze field=id text='ventures.house.1137'

{
    "tokens": [
        {
            "end_offset": 14,
            "position": 0,
            "start_offset": 0,
            "token": "ventures.house",
            "type": "<ALPHANUM>"
        },
        {
            "end_offset": 19,
            "position": 1,
            "start_offset": 15,
            "token": "1137",
            "type": "<NUM>"
        }
    ]
}

... and a search for an id returns indeed ALL ids that start with ventures.house.

Why is that and how can I come to the EXACT matching?

It's ES 5.2.

Upvotes: 0

Views: 307

Answers (3)

Christian Gintenreiter
Christian Gintenreiter

Reputation: 168

Have you tried defining the field 'id' as keyword ?

In this case it does not get analyzed but stored as is. When I understand your question correctly this is what you want.

{  
 "id":{
   "type":"keyword"
 }
}

See https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html

I hope this helped. Christian

Upvotes: 0

shredding
shredding

Reputation: 5591

I misread the mapping, it looks like my elasticsearch-dsl library does not create a keyword directly, but adds it as a subfield.

Upvotes: 0

Dennis Ich
Dennis Ich

Reputation: 3775

From https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping-intro.html#_index_2

not_analyzed: Index this field, so it is searchable, but index the value exactly as specified. Do not analyze it.

{
  "tag": {
      "type":     "string",
      "index":    "not_analyzed"
  }
}

Upvotes: 1

Related Questions