【问题标题】:What does elasticsearch _search api stats tag do?elasticsearch _search api stats 标签有什么作用?
【发布时间】:2018-09-25 09:27:48
【问题描述】:

我正在尝试在用户使用 _search API 时收集数据,我偶然发现了一个可以放入搜索查询的标签,这可能会为我简化一切,但我找不到足够的信息。

_search 正文中的 stats 标记是否会影响任何内容?喜欢返回的结果吗?

我能在上面找到的唯一信息是这个页面https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html,它声明的只是String、String[]、Boolean — 用于记录和统计目的的请求的特定标记。 elasticsearch 是否真的在某处记录它?

我的 _search 请求示例:

Kibana

GET myindex/doc/_search
{
  "query": {
    "match_all": {}
  }, 
  "stats": ["my string of data"]
}

卷曲

curl -XGET "http://localhost:9200/myindex/doc/_search" -H 'Content-Type: application/json' -d'
{
  "query": {
    "match_all": {}
  }, 
  "stats": ["my string of data"]
}'

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    _search 查询中的stats 关键字用于定义一些统计信息组,您可以稍后使用_stats API 查询这些统计信息组。例如,假设您使用my-query 组查询myindex

    curl -XGET "http://localhost:9200/myindex/doc/_search" -H 'Content-Type: application/json' -d'
    {
      "query": {
        "match_all": {}
      }, 
      "stats": ["my-query"]
    }'
    

    然后您可以使用以下查询获取该组的index-level search statistics

    curl -XGET "http://localhost:9200/myindex/_stats/search?groups=my-stats"
    

    你会得到这样的东西:

    {
      "_shards": {
        "total": 2,
        "successful": 2,
        "failed": 0
      },
      "_all": {
        "primaries": {
          "search": {
            "open_contexts": 0,
            "query_total": 5806,
            "query_time_in_millis": 73948,
            ...
            "groups": {
              "my-query": {                         <----------
                "query_total": 8,
                "query_time_in_millis": 81,
                ...
              }
            }
          }
        },
        "total": {
          "search": {
            "open_contexts": 0,
            "query_total": 5806,
            "query_time_in_millis": 73948,
            ...
            "groups": {
              "my-query": {                         <----------
                "query_total": 8,
                "query_time_in_millis": 81,
                ...
              }
            }
          }
        }
      },
      "indices": {
        "listings-master": {
          "uuid": "oUYHBiU8RVayI95uCw3Clg",
          "primaries": {
            "search": {
              "open_contexts": 0,
              "query_total": 5806,
              "query_time_in_millis": 73948,
              ...
              "groups": {
                "my-query": {                         <----------
                  "query_total": 8,
                  "query_time_in_millis": 81,
                  ...
                }
              }
            }
          },
          "total": {
            "search": {
              "open_contexts": 0,
              "query_total": 5806,
              "query_time_in_millis": 73948,
              ...
              "groups": {
                "my-query": {                         <----------
                  "query_total": 8,
                  "query_time_in_millis": 81,
                  ...
                }
              }
            }
          }
        }
      }
    }
    

    【讨论】:

    • 非常感谢。哇,我需要对此进行试验,因为 _stats API 似乎实际上可以完美地解决我的问题。
    • 酷,很高兴它有帮助!
    猜你喜欢
    • 1970-01-01
    • 2022-07-11
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 2016-06-15
    相关资源
    最近更新 更多