E.S版本: 5.5.2
示例文档:
{
"_index": "test_index",
"_type": "doc",
"_id": "5485044",
"_score": 1,
"_routing": "135767",
"_source": {
"e_id": 135767
}
}
要求:要获取所有文档,其中_routing与e_id不匹配
查询:
GET test_index/_search
{
"size": 1000,
"query": {
"bool": {
"filter": {
"script": {
"script": "'_routing'!=doc['e_id'].value.toString()"
}
}
}
}
结果:我得到的答复不是预期的。带有_routing == e_id的O / P文档也已匹配。
最佳答案
无法在搜索查询中访问_routing
值。
但是,您可以做的是先标记所有e_id
值不同于_routing
值的文档,然后查询标记的文档。
首先,通过查询运行更新以标记所有文档
POST test_index/_update_by_query
{
"script": {
"source": "ctx._source.routingOk = (ctx._routing == ctx._source.e_id.toString())",
"lang": "painless"
}
}
然后查询具有routingOk: false
的文档:GET test/_search?q=routingOk:false
关于elasticsearch - 将_routing与脚本中文档的另一个字段进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63260058/