【问题标题】:Elastic Search need to return only 1 field from a range.弹性搜索只需要从一个范围内返回 1 个字段。
【发布时间】:2017-08-03 04:12:30
【问题描述】:

刚刚开始使用 curl 和 Elastic Search 查询。我有这个问题:

{
  "query": {
           "range": {
                    "_timestamp": {
                            "gt": "now-30m"
        }
      }
    }
}'

效果很好,但会返回 30 分钟窗口中的所有数据。如何优化搜索以仅返回 ID 字段?

感谢您的帮助。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    这叫源过滤https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html

    {
      "_source": [ "ID" ],
      "query": {
               "range": {
                        "_timestamp": {
                                "gt": "now-30m"
            }
          }
        }
    }
    

    【讨论】:

    • 做到了。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-20
    • 2021-01-28
    • 2023-03-09
    • 2016-12-29
    • 2015-05-06
    • 1970-01-01
    相关资源
    最近更新 更多