将 _routing 与脚本中文档的另一个字段进行比较
Comparing _routing with another field of document in script
E.S版本:5.5.2
示例文档:
{
"_index": "test_index",
"_type": "doc",
"_id": "5485044",
"_score": 1,
"_routing": "135767",
"_source": {
"e_id": 135767
}
}
要求:
获取所有文档where-in_routing与e_id
不匹配
查询:
GET test_index/_search
{
"size": 1000,
"query": {
"bool": {
"filter": {
"script": {
"script": "'_routing'!=doc['e_id'].value.toString()"
}
}
}
}
结果: 我得到的响应不是预期的。 O/P _routing == e_id 的文档也得到匹配。
无法访问搜索查询中的 _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
E.S版本:5.5.2
示例文档:
{
"_index": "test_index",
"_type": "doc",
"_id": "5485044",
"_score": 1,
"_routing": "135767",
"_source": {
"e_id": 135767
}
}
要求:
获取所有文档where-in_routing与e_id
不匹配查询:
GET test_index/_search
{
"size": 1000,
"query": {
"bool": {
"filter": {
"script": {
"script": "'_routing'!=doc['e_id'].value.toString()"
}
}
}
}
结果: 我得到的响应不是预期的。 O/P _routing == e_id 的文档也得到匹配。
无法访问搜索查询中的 _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