弹性搜索中的特殊字符“ - ”

时间:2013-11-04 07:20:31

标签: elasticsearch

“ - ”的行为类似于或作为例如我正在搜索“t-link”,然后它显示的结果包含“t-link”以及“t”,为什么它给出了两个术语,但我对“t-link”感兴趣,为什么会这样发生呢?我怎样才能从中恢复过来?

1 个答案:

答案 0 :(得分:8)

Elasticsearch默认使用standard analyzer表示字符串。

基本上,你的字符串被标记为两个标记,小写:

  • t
  • 链接

如果您需要了解elasticsearch与您的字段的内容,请使用_analyze API

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

如果您不想这样做,请确保put the right mapping为该字段,并根据您的要求使用simple analyzerkeyword analyzer或根本不使用分析器。另请参阅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"}
        }
    }
}
'

使用此message字段将使用simple分析器进行分析,other字段将不会被分析。

相关问题