Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strootman/90ee221198c71dfad34f6abb15ed837a to your computer and use it in GitHub Desktop.
Save strootman/90ee221198c71dfad34f6abb15ed837a to your computer and use it in GitHub Desktop.
Adding a new analyzer into existing index in Elasticsearch (requires close/open the index). Tested with Elasticsearch 0.19.12.
// create an index with an analyzer "myindex"
curl -X PUT localhost:9200/myindex -d '
{
"settings" : {`
"index":{
"number_of_replicas":0,
"number_of_shards":1,
"analysis":{
"analyzer":{
"first":{
"type":"whitespace"
}
}
}
}
}
}'
// verify analyzers for "myindex"
curl -XGET 'http://localhost:9200/_cluster/state?pretty&filter_nodes=true&filter_routing_table=true&filter_indices=myindex'
# {
# "cluster_name" : "elasticsearch",
# "blocks" : { },
# "metadata" : {
# "templates" : { },
# "indices" : {
# "myindex" : {
# "state" : "open",
# "settings" : {
# "index.number_of_replicas" : "0",
# "index.number_of_shards" : "1",
# "index.analysis.analyzer.first.type" : "whitespace",
# "index.version.created" : "191299"
# },
# "mappings" : { },
# "aliases" : [ ]
# }
# }
# }
# }
// try to add a new analyzer
curl -XPUT 'localhost:9200/myindex/_settings' -d '{
"analysis" : {
"analyzer":{
"second":{
"type":"custom",
"tokenizer":"whitespace",
"filter":["lowercase"]
}
}
}
}'
# {"ok":true}
// but in fact index setting is not modified - the following is found in the log
[WARN ][cluster.metadata ] [Captain Omen] [myindex] ignoring non dynamic index level settings for open indices: [index.analysis.analyzer.second.type, index.analysis.analyzer.second.tokenizer, index.analysis.analyzer.second.filter.0]
// close the index
curl -XPOST 'localhost:9200/myindex/_close'
# {"ok":true,"acknowledged":true}
// we can verify index is closed
curl -XGET 'http://localhost:9200/_cluster/state?pretty&filter_nodes=true&filter_routing_table=true&filter_indices=myindex'
# {
# "cluster_name" : "elasticsearch",
# "blocks" : {
# "indices" : {
# "myindex" : {
# "4" : {
# "description" : "index closed", // <--- myindex is closed
# "retryable" : false,
# "levels" : [ "read", "write" ]
# }
# }
# }
# },
# "metadata" : {
# "templates" : { },
# "indices" : {
# "myindex" : {
# "state" : "close", // <--- state: close
# "settings" : {
# "index.number_of_replicas" : "0",
# "index.number_of_shards" : "1",
# "index.analysis.analyzer.first.type" : "whitespace",
# "index.version.created" : "191299"
# },
# "mappings" : { },
# "aliases" : [ ]
# }
# }
# }
# }
// try to add a new analyzer again
curl -XPUT 'localhost:9200/myindex/_settings' -d '{
"analysis" : {
"analyzer":{
"second":{
"type":"custom",
"tokenizer":"whitespace",
"filter":["lowercase"]
}
}
}
}'
# {"ok":true}
// we can add a new analyzer now
curl -XGET 'http://localhost:9200/_cluster/state?pretty&filter_nodes=true&filter_routing_table=true&filter_indices=myindex'
# {
# "cluster_name" : "elasticsearch",
# "blocks" : {
# "indices" : {
# "myindex" : {
# "4" : {
# "description" : "index closed",
# "retryable" : false,
# "levels" : [ "read", "write" ]
# }
# }
# }
# },
# "metadata" : {
# "templates" : { },
# "indices" : {
# "myindex" : {
# "state" : "close",
# "settings" : {
# "index.number_of_replicas" : "0",
# "index.number_of_shards" : "1",
# "index.analysis.analyzer.first.type" : "whitespace",
# "index.version.created" : "191299",
# "index.analysis.analyzer.second.tokenizer" : "whitespace",
# "index.analysis.analyzer.second.type" : "custom",
# "index.analysis.analyzer.second.filter.0" : "lowercase"
# },
# "mappings" : { },
# "aliases" : [ ]
# }
# }
# }
# }
// open the index now
curl -XPOST 'localhost:9200/myindex/_open'
# {"ok":true,"acknowledged":true}
// now everything seems to be ok
curl -XGET 'http://localhost:9200/_cluster/state?pretty&filter_nodes=true&filter_routing_table=true&filter_indices=myindex'
# {
# "cluster_name" : "elasticsearch",
# "blocks" : { },
# "metadata" : {
# "templates" : { },
# "indices" : {
# "myindex" : {
# "state" : "open",
# "settings" : {
# "index.number_of_replicas" : "0",
# "index.number_of_shards" : "1",
# "index.analysis.analyzer.first.type" : "whitespace",
# "index.version.created" : "191299",
# "index.analysis.analyzer.second.tokenizer" : "whitespace",
# "index.analysis.analyzer.second.type" : "custom",
# "index.analysis.analyzer.second.filter.0" : "lowercase"
# },
# "mappings" : { },
# "aliases" : [ ]
# }
# }
# }
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment