关键字类型嵌套文档的范围查询

Range query on Nested Documents for Keyword Type

我有这样的文档结构。对于下面的两个文档,我们有称为交互信息的嵌套文档。我只需要获取标题持续时间且其值大于 60

的文档

这里的捕获值字段是关键字,而不是整数。我知道只有整数范围查询才会被执行。是否有任何可能的方法来查找持续时间大于 60 的文档(无痛查询或脚本查询)。比如将值Field转换成Integer然后搜索文档

{
    "key": "f07ff9ba-36e4-482a-9c1c-d888e89f926e",
    "interactionInfo": [
      {
        "title": "duration",
        "value": "11"
      },
      {
        "title": "timetaken",
        "value": "9"
      },
      {
        "title": "talk_time",
        "value": "145"
      }
    ]
  },
  {
    "key": "f07ff9ba-36e4-482a-9c1c-d888e89f926e",
    "interactionInfo": [
      {
        "title": "duration",
        "value": "120"
      },
      {
        "title": "timetaken",
        "value": "9"
      },
      {
        "title": "talk_time",
        "value": "60"
      }
    ]
  }

我已添加脚本以获取 interactionInfo.value>"somevalue"。脚本很慢,最好在索引时解决这个问题并使用范围查询。

索引:

{
  "index15" : {
    "mappings" : {
      "properties" : {
        "interactionInfo" : {
          "type" : "nested",
          "properties" : {
            "title" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "value" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
        "key" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}

查询:

{
  "query": {
    "nested": {
      "path": "interactionInfo",
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "interactionInfo.title.keyword": {
                  "value": "duration"
                }
              }
            },
            {
              "script": {
                "script": {
                "source":"def val=Integer.parseInt(doc['interactionInfo.value.keyword'].value); if(val>params.value) return true; else return false;",
                "params": {
                  "value":10
                }
                }
              }
            }
          ]
        }
      },
      "inner_hits": {}
    }
  }
}