1

有什么办法可以隐藏一些作为响应返回的公共字段。

例如,如果我得到如下响应:

{
  "took": 74,
  "timed_out": false,
  "_shards": {
    "total": 15,
    "successful": 15,
    "failed": 0
  },
  "hits": {
    "total": 24,
    "max_score": 0.15932977,
    "hits": [
      {
        "_index": "prashant",
        "_type": "session",
        "_id": "LeIDrUNmSKGC5Sl9Y8O0Zw",
        "_score": 0.15932977,
        "fields": {
          "Time": [
            "2014-01-08T15:01:26"
          ]
        }
      },
      {
        "_index": "prashant",
        "_type": "session",
        "_id": "dlpQGXk_TOyfNnUEG6skeQ",
        "_score": 0.14296037,
        "fields": {
          "Time": [
            "2014-01-08T15:01:26"
          ]
        }
      }
    ]
  }
}

现在我希望 ES 响应没有take、timed_out、_shards、total、success、failed值以及我不想要_index、_type的名称, 因为我正在执行对特定索引和类型的查询。

那么有没有办法以这种方式过滤 ES 响应?

4

2 回答 2

3

使用“ filter_path ”查询参数。在您的示例中,要仅包含所有结果的 _source 和 _id 字段(从而排除响应中的所有其他元数据),请使用:

http://your-es-cluster?filter_path=hits.hits._source,hits.hits._id

我认为它从 1.6 开始就在其余的 api 中。

要进一步过滤和限制 _source 中的字段,请使用普通的_source 参数过滤。例如:

http://your-es-cluster?filter_path=hits.hits._source,hits.hits._id&_source=Time

于 2016-02-15T20:42:20.117 回答
1

您可以通过在请求的搜索查询部分中指定要返回的字段来限制搜索响应。

"search_request": {
  "fields": [ "title", "content" ],
  "query": ...
},

这是 Elasticsearch 的标准字段过滤器,它不是特定于集群的。请记住,您必须包含稍后将用于聚类的字段。请参阅插件的文档(“关于字段映射的更多信息”)。

于 2014-03-19T10:08:57.433 回答