Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Special Character "- " in the Elastic Search acting

"-" is acting like a or operator for e.g. I am searching "t-link", then it showing the result containing "t-link" as well as "t", why it is giving two terms, but i interested in the "t-link", why it is happening so? How can i recover from it?

like image 472
Deep Saxena Avatar asked Nov 04 '13 07:11

Deep Saxena


1 Answers

Elasticsearch is using by default the standard analyzer for strings.

Basically, your string is tokenized in two tokens, lowercased:

  • t
  • link

If you need to know what does elasticsearch with your fields, use the _analyze API.

$ curl -XGET 'localhost:9200/_analyze?analyzer=standard' -d 't-link'
$ curl -XGET 'localhost:9200/_analyze?analyzer=simple' -d 't-link'

If you don't want that, make sure you put the right mapping for that field and use either a simple analyzer or a keyword analyzer or no analyzer at all depending on your requirements. See also String core type.

$ curl -XPUT 'http://localhost:9200/twitter/tweet/_mapping' -d '
{
    "tweet" : {
        "properties" : {
            "message" : {"type" : "string", "analyzer" : "simple"},
            "other" : {"type" : "string", "index" : "not_analyzed"}
        }
    }
}
'

Using this form message field will be analyzed with simple analyzer and other field won't be analyzed at all.

like image 134
dadoonet Avatar answered Oct 07 '22 12:10

dadoonet