首先,我想设置ES的默认分析器,但失败了.然后根据其他问题和网站,我试图设置一个索引的默认分析器.但也有一些问题.
我已经配置了ik分析器,我可以设置一些字段的分析器,这是我的命令:
curl -XPUT localhost:9200/test
curl -XPUT localhost:9200/test/test/_mapping -d'{
"test":{
"properties":{
"name":{
"type":"string",
"analyzer":"ik"
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)
并得到消息:
{"acknowledged":true}
Run Code Online (Sandbox Code Playgroud)
它也符合我的愿望.
但是,如果我尝试设置索引的默认分析器:
curl -XPOST localhost:9200/test1?pretty -d '{ "index":{
"analysis" : {
"analyzer" : {
"default" : {
"type" : "ik"
}
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)
我会收到错误消息:
{
"error" : {
"root_cause" : [ {
"type" : "index_creation_exception",
"reason" : "failed to create index"
} ],
"type" : "illegal_argument_exception",
"reason" : "no default analyzer configured"
},
"status" : 400
}
Run Code Online (Sandbox Code Playgroud)
太奇怪了,不是吗?期待您对此问题的看法.谢谢!:)
这是有关条款的Elasticsearch官方网站:https : //www.elastic.co/guide/en/elasticsearch/reference/2.1/query-dsl-terms-query.html
如我们所见,如果要执行术语查找机制查询,则应使用以下命令:
curl -XGET localhost:9200/tweets/_search -d '{
"query" : {
"terms" : {
"user" : {
"index" : "users",
"type" : "user",
"id" : "2",
"path" : "followers"
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)
但是,如果我想通过其他用户领域进行查询怎么办。假设用户还有其他一些字段,例如名称,我是否可以使用术语查找机制通过给用户提供名称而不是ID来查找推文。我试图使用这样的命令:
curl -XGET localhost:9200/tweets/_search -d '{
"query" : {
"terms" : {
"user" : {
"index" : "users",
"type" : "user",
"name" : "Jane",
"path" : "followers"
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)
但发生错误。期待您的帮助。谢谢!