[英]Filter out metadata fields and only return source fields in elasticsearch
有沒有辦法告訴elasticsearch不返回任何元數據? 目前我可以選擇要在源中返回哪些字段。 但我只想要源代碼中的字段。 我寧願沒有返回元數據,因為我不需要它,並會節省一些不必要的解析和傳輸等。
我找到了Elasticsearch - 如何只返回數據,而不是元信息? 更老的問題,有人評論說當時不可能做到這一點。 想知道這個功能是否已添加或仍然缺失?
所有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
}
]
}
}
在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
如果要過濾_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"}
} ]
}
}
如果我們知道它並不困難:)
http://localhost:9200/***{index_name}***/***{type}***/_search?pretty&filter_path=took,hits.hits._id,hits.hits._score,**hits.hits._source**
我在查詢中不知道這樣的選項。 可以在get by Id請求中執行此操作。
/{index}/{type}/{id}/_source
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-get.html#_source
filter_path
(響應過濾)對filter_path
的1.5版本沒有任何影響。
除非該選項具有不同的名稱或已在文檔中移動,否則它首先在1.6版中添加。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.