首页 文章

弹性搜索运行两次groovy脚本,这是一个错误吗?

提问于
浏览
0

我发现了脚本查询的一些意外行为(脚本在一个简单的查询中执行两次) .

我的配置:弹性搜索版本:2.4.6(问题仍然在弹性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(只返回得分并打印出来):

{
     "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 GET'localhost:9200 / default / type1 / _search'@ query_with_script.json

6)为什么在弹性搜索日志中我看到脚本在两个不同的时间执行?这是一个错误吗?

Score is 0.19178301095962524 for document [1] at 1516586818596
Score is 0.19178301095962524 for document [1] at 1516586818606

非常感谢!

1 回答

  • 1

    您应该删除explain标志,因为它可能是脚本执行两次的原因 .

相关问题