获取我的Elasticsearch集群的奇怪行为:似乎它不再看到静态groovy脚本了。
它抱怨"动态脚本被禁用"但是我正在使用说明脚本和正确的名称。
他们以前做过工作,现在无法理解改变了什么。
以下是我用来重现问题的步骤:
使用映射定义一个字符串字段和嵌套对象创建索引:
curl -XPUT localhost:9200/test/ -d '{
"index": {
"number_of_shards": 1,
"number_of_replicas": 0
}
}'
curl -XPUT localhost:9200/test/_mapping/testtype -d '{
"testtype": {
"properties": {
"name": {
"type": "string"
},
"features": {
"type": "nested",
"properties": {
"key": {
"type": "string",
"value": {
"type": "string"
}
}
}
}
}
}
}'
响应:
{
"acknowledged": true
}
在那里放一个对象:
curl -XPUT localhost:9200/test/testtype/1 -d '{
"name": "hello",
"features": []
}'
使用脚本调用更新:
curl -XPOST http://localhost:9200/test/testtype/1/_update -d '{
"script": "add-feature-if-not-exists",
"params": {
"new_feature": {
"key": "Manufacturer",
"value": "China"
}
}
}'
响应:
{
"error": "RemoteTransportException[[esnew1][inet[/78.46.100.39:9300]][indices:data/write/update]];
nested: ElasticsearchIllegalArgumentException[failed to execute script];
nested: ScriptException[dynamic scripting for [groovy] disabled]; ",
"status": 400
}
获取" [groovy]禁用的动态脚本" - 但我在"脚本"中使用了对静态脚本名称的引用。领域。但是,如果脚本名称不正确,我会看到此消息。但看起来它是正确的:
该脚本位于/ etc / elasticsearch / scripts /中。 验证/ etc / elasticsearch是否用作配置目录:
ps aux | grep elas
elastic+ 944 0.8 4.0 21523740 1322820 ? Sl 15:35 0:39 /usr/lib/jvm/java-7-oracle/bin/java -Xms16g -Xmx16g -Xss256k -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Delasticsearch -Des.pidfile=/var/run/elasticsearch.pid -Des.path.home=/usr/share/elasticsearch -cp :/usr/share/elasticsearch/lib/elasticsearch-1.4.0.jar:/usr/share/elasticsearch/lib/*:/usr/share/elasticsearch/lib/sigar/* -Des.default.config=/etc/elasticsearch/elasticsearch.yml -Des.default.path.home=/usr/share/elasticsearch -Des.default.path.logs=/var/log/elasticsearch -Des.default.path.data=/var/lib/elasticsearch -Des.default.path.work=/tmp/elasticsearch -Des.default.path.conf=/etc/elasticsearch org.elasticsearch.bootstrap.Elasticsearch
看看脚本是否存在:
$ ls -l /etc/elasticsearch/ total 24 -rw-r--r-- 1 root root
total 24
-rw-r--r-- 1 root root 13683 Nov 25 14:52 elasticsearch.yml
-rw-r--r-- 1 root root 1511 Nov 15 04:13 logging.yml
drwxr-xr-x 2 root root 4096 Nov 25 15:07 scripts
$ ls -l /etc/elasticsearch/scripts/ total 8 -rw-r--r-- 1
total 8
-rw-r--r-- 1 elasticsearch elasticsearch 438 Nov 25 15:07 add-feature-if-not-exists.groovy
-rw-r--r-- 1 elasticsearch elasticsearch 506 Nov 23 02:52 add-review-if-not-exists.groovy
有关为何发生这种情况的任何提示?我还检查了什么?
更新:群集有两个节点。
在node1上配置:
cluster.name: myclustername
node.name: "esnew1"
node.master: true
node.data: true
bootstrap.mlockall: true
network.host: zz.zz.zz.zz
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: ["esnew1.company.com","esnew2.company.com"]
index.store.type: niofs
script.disable_dynamic: true
script.auto_reload_enabled: true
watcher.interval: 30s
节点2上的配置:
cluster.name: myclustername
node.name: "esnew2"
node.master: true
node.data: true
bootstrap.mlockall: true
metwork.bind_host: 127.0.0.1,zz.zz.zz.zz
network.publish_host: zz.zz.zz.zz
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: ["esnew1.company.com","esnew2.company.com"]
index.store.type: niofs
script.disable_dynamic: true
script.auto_reload_enabled: true
watcher.interval: 30s
Elasticsearch版本:
$ curl localhost:9200
{
"status" : 200,
"name" : "esnew2",
"cluster_name" : "myclustername",
"version" : {
"number" : "1.4.0",
"build_hash" : "bc94bd81298f81c656893ab1ddddd30a99356066",
"build_timestamp" : "2014-11-05T14:26:12Z",
"build_snapshot" : false,
"lucene_version" : "4.10.2"
},
"tagline" : "You Know, for Search"
}
P.S。:一个观察证实,ES可能只是没有看到脚本:在某个时刻,ES看到了一个脚本,但没有看到另一个脚本。重新启动后,它们没有看到任何一个。
P.P.S。:剧本:
do_add = false
def stringsEqual(s1, s2) {
if (s1 == null) {
return s2 == null;
}
return s1.equalsIgnoreCase(s2);
}
for (item in ctx._source.features) {
if (stringsEqual(item['key'], new_feature.key) {
if (! stringsEqual(item['value'], new_feature.value) {
item.value = new_feature.value;
}
} else {
do_add = true
}
}
if (do_add) {
ctx._source.features.add(new_feature)
}