问题
I am using Grails with the ElasticSearch Plugin. It works fine, but I need to define the settings and analyzer.
How can I do that?
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" }
}
}
}
}
回答1:
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" }
}
}
}
}'
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.
来源:https://stackoverflow.com/questions/18188370/how-can-i-define-settings-and-analyzer-for-elasticsearch