Elasticsearch 运行 groovy 脚本两次,这是一个错误吗?
Elastic search runs groovy scripts two times, is it a bug?
我发现脚本查询有一些意外行为(脚本在一个简单查询中执行了两次)。
我的配置:elastic search版本:2.4.6(elastic 5.6仍有问题)
我的elasticsearch.yml:
script.indexed: true
重现问题的步骤:
1) 我有一个简单的文档,doc1.json:
{
"id": "1",
"tags": "t1"
}
2) 在 Elastic 中插入 doc1:
http PUT localhost:9200/default/type1/1 @doc1.json
3) 我有一个简单的 groovy 脚本,script1.json(只是 returns 乐谱并打印出来):
{
"script": "println('Score is ' + _score * 1.0 + ' for document ' + doc['id'] + ' at ' + DateTime.now().getMillis()); return _score;"
}
4) 注册脚本1:
http POST 'localhost:9200/_scripts/groovy/script1' @script1.json
5) 执行这个 query_with_script.json:
{
"query":{
"function_score":{
"query":{
"bool":{
"must":{
"match":{
"tags":{
"query":"t1",
"type":"boolean"
}
}
}
}
},
"functions":[
{
"script_score":{
"script":{
"id":"script1",
"lang":"groovy"
}
}
}
],
"boost_mode":"replace"
}
},
"explain" : true
}
http 获取 'localhost:9200/default/type1/_search' @query_with_script.json
6) 为什么在 Elastic 搜索日志中我看到脚本在两个不同的时间执行?这是一个错误吗?
Score is 0.19178301095962524 for document [1] at 1516586818596
Score is 0.19178301095962524 for document [1] at 1516586818606
非常感谢!
您可能应该删除解释标志,因为它可能是脚本执行两次的原因。
我发现脚本查询有一些意外行为(脚本在一个简单查询中执行了两次)。
我的配置:elastic search版本:2.4.6(elastic 5.6仍有问题)
我的elasticsearch.yml:
script.indexed: true
重现问题的步骤:
1) 我有一个简单的文档,doc1.json:
{
"id": "1",
"tags": "t1"
}
2) 在 Elastic 中插入 doc1:
http PUT localhost:9200/default/type1/1 @doc1.json
3) 我有一个简单的 groovy 脚本,script1.json(只是 returns 乐谱并打印出来):
{
"script": "println('Score is ' + _score * 1.0 + ' for document ' + doc['id'] + ' at ' + DateTime.now().getMillis()); return _score;"
}
4) 注册脚本1:
http POST 'localhost:9200/_scripts/groovy/script1' @script1.json
5) 执行这个 query_with_script.json:
{
"query":{
"function_score":{
"query":{
"bool":{
"must":{
"match":{
"tags":{
"query":"t1",
"type":"boolean"
}
}
}
}
},
"functions":[
{
"script_score":{
"script":{
"id":"script1",
"lang":"groovy"
}
}
}
],
"boost_mode":"replace"
}
},
"explain" : true
}
http 获取 'localhost:9200/default/type1/_search' @query_with_script.json
6) 为什么在 Elastic 搜索日志中我看到脚本在两个不同的时间执行?这是一个错误吗?
Score is 0.19178301095962524 for document [1] at 1516586818596
Score is 0.19178301095962524 for document [1] at 1516586818606
非常感谢!
您可能应该删除解释标志,因为它可能是脚本执行两次的原因。