访问elasticsearch匹配查询中的脚本字段

时间:2016-09-11 12:05:20

标签: elasticsearch

我有类似以下的查询

{
  "script_fields": {
    "my_script_field": {
      "script": "..."
    }
  },
  "query": {
    "match": {
      "my_script_field":"*"
    }
  }
}

并返回空。

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 10,
    "successful": 10,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

我可以看到脚本实际上只是重新调整所有内容 像:

{
  "fields": [
  "_source"
  ],
  "script_fields": {
    "my_script_field": {
      "script": "..."
    }
  },
  "query": {
    match_all: {}
  }
}

示例结果:

  "hits": {
    "total": 1008681,
    "max_score": 1,
    "hits": [
      {
        "_index": "logstash-2016.08.27",
        "_type": "traffic",
        "_id": "AVbLDW8qw2vffjMOfTxb",
        "_score": 1,
        "_source": {
          "@version": "1",
          "@timestamp": "2016-08-27T06:11:46.000Z",
           .................
          }
        },
        "fields": {
          "my_scripted_field": [
            "Asia"
          ]
        }

但我似乎无法以任何其他方式在查询上下文中访问它。

我的问题是:

  • 脚本输出保存在内存中的哪个位置? (_fields?)
  • 如何通过查询访问它? (不将脚本复制到过滤器脚本)

谢谢!

0 个答案:

没有答案