Standard Analyzer
elasticsearch实现全文索引,首先要确定分词器,elasticsearch默认有很多分词器,你可以参考elasticsearch的官方文档。我们在这里介绍一下Standard Analyzer。如以下代码:
curl -XGET 'http://localhost:9200/_analyze?analyzer=standard' -d 'This is a demo'
{
"tokens" : [ {
"token" : "this",
"start_offset" : 0,
"end_offset" : 4,
"type" : "ALPHANUM",
"position" : 1
}, {
"token" : "is",
"start_offset" : 5,
"end_offset" : 7,
"type" : "ALPHANUM",
"position" : 2
}, {
"token" : "a",
"start_offset" : 8,
"end_offset" : 9,
"type" : "ALPHANUM",
"position" : 3
}, {
"token" : "demo",
"start_offset" : 10,
"end_offset" : 14,
"type" : "ALPHANUM",
"position" : 4
} ]
}
我们会看到以上结果,是不是把这句话都分成了一个一个的单词。
ES使用默认的全局analyzer, 默认的analyzer是标准analyzer, 这个标准analyzer有三个filter:token filter, lowercase filter和stop token filter。
返回结果中,是不是T变为t了,如果需要不变的话, 你需要修改你的analyzer。
试一试上面的例子吧!