过滤掉元数据字段,仅返回elasticsearch中的源字段

bag*_*agi 29 elasticsearch

有没有办法告诉elasticsearch不返回任何元数据?目前我可以选择要在源中返回哪些字段.但我只想要源代码中的字段.我宁愿没有返回元数据,因为我不需要它,并会节省一些不必要的解析和传输等.

我找到了Elasticsearch - 如何只返回数据,而不是元信息?更老的问题,有人评论说当时不可能做到这一点.想知道这个功能是否已添加或仍然缺失?

The*_*emz 28

response_filtering

所有REST API都接受filter_path参数,该参数可用于减少elasticsearch返回的响应.此参数采用逗号分隔的过滤器列表,用点表示法表示:

curl -XGET 'localhost:9200/_search?pretty&filter_path=took,hits.hits._id,hits.hits._score'
{
  "took" : 3,
  "hits" : {
    "hits" : [
      {
        "_id" : "3640",
        "_score" : 1.0
      },
      {
        "_id" : "3642",
        "_score" : 1.0
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

在python中

def get_all( connection, index_name, type_name ):

    query = {
        "match_all":{}
    }

    result = connection.search( index_name, type_name,
             {"query": query},
             filter_path= ["took", "hits.hits._id", "hits.hits.score"])

    return result
Run Code Online (Sandbox Code Playgroud)

如果要过滤_source字段,则应考虑将已存在的 _source参数(请参阅获取API以获取更多详细信息)与filter_path参数组合,如下所示:

curl -XGET 'localhost:9200/_search?pretty&filter_path=hits.hits._source&_source=title'
{
  "hits" : {
    "hits" : [ {
      "_source":{"title":"Book #2"}
    }, {
      "_source":{"title":"Book #1"}
    }, {
      "_source":{"title":"Book #3"}
    } ]
  }
}
Run Code Online (Sandbox Code Playgroud)


Mar*_*man 8

如果我们知道它并不困难:)

http://localhost:9200/***{index_name}***/***{type}***/_search?pretty&filter_path=took,hits.hits._id,hits.hits._score,**hits.hits._source**
Run Code Online (Sandbox Code Playgroud)

  • HTTP://本地主机:9200/{INDEX_NAME}/{类型} /_search?pretty&filter_path=hits.hits._source (2认同)

Jet*_*die 4

我不知道查询中存在这样的选项。可以在 get by Id 请求中执行此操作。

/{index}/{type}/{id}/_source
Run Code Online (Sandbox Code Playgroud)

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-get.html#_source