如何定义ElasticSearch的设置和分析器? [英] How can I define Settings and Analyzer for ElasticSearch?
问题描述
我正在使用Grails与 ElasticSearch Plugin 。它工作正常,但我需要定义设置和分析器。
I am using Grails with the ElasticSearch Plugin. It works fine, but I need to define the settings and analyzer.
我该怎么做?
我想使用以下设置和映射:
I want to use the following settings and mappings:
{
"settings" : {
"index" : {
"analysis" : {
"analyzer" : {
"autocomplete" : "engram",
"filter" : ["lowercase"]
}
},
"tokenizer" : {
"engram" : {
"type" : "edgeNgram",
"min_gram" : 3,
"max_gram" : 10
}
}
}
}
},
"mappings" : {
"contacts" : {
"name" : {
"index" : "string",
"index_analyzer" : "autocomplete",
"index" : "analyzed", "search_analyzer" : "standard"
},
"country" : { "type" : "string" }
}
}
}
}
推荐答案
正如dmahaptro所说,使用Elasticsearch的Rest API将会起作用。来自 http://www.elasticsearch.org/guide/reference / api / admin-indices-create-index / 在mappings标题下,您可以将以下内容复制并粘贴到您的shell中:
As dmahaptro suggests, using Elasticsearch's Rest API would work. From http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index/ under the "mappings" header, you can copy and paste the following into your shell:
curl -XPOST localhost:9200/index_name -d '{
"settings" : {
"index" : {
"analysis" : {
"analyzer" : {
"autocomplete" : "engram",
"filter" : ["lowercase"]
}
},
"tokenizer" : {
"engram" : {
"type" : "edgeNgram",
"min_gram" : 3,
"max_gram" : 10
}
}
}
}
},
"mappings" : {
"contacts" : {
"name" : {
"index" : "string",
"index_analyzer" : "autocomplete",
"index" : "analyzed", "search_analyzer" : "standard"
},
"country" : { "type" : "string" }
}
}
}
}'
检查您的索引是否使用正确的设置创建的方法是使用头插件: https://github.com/mobz/elasticsearch-head 。在浏览器中启动头插件,然后单击所有索引及其设置,映射等的群集状态选项卡。
A way to check that your index was created with the correct settings is to use the head plugin: https://github.com/mobz/elasticsearch-head. Fire up the head plugin in your browser and click the "Cluster State" tab for all of your indexes and their settings, mappings, etc.
这篇关于如何定义ElasticSearch的设置和分析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!