有沒有辦法告訴elasticsearch不返回任何元數據?目前我可以選擇我想在源代碼中返回哪些字段。但我只想要源代碼中的字段。我寧願沒有元數據返回,因爲我不需要它,並會節省一些不必要的解析和運輸等。篩選出元數據字段,並只返回elasticsearch中的源字段
我發現Elasticsearch - how to return only data, not meta information?老問題,其中有人評論說,它不可能做到這一點。想知道這個功能是否已被添加或仍然失蹤?
有沒有辦法告訴elasticsearch不返回任何元數據?目前我可以選擇我想在源代碼中返回哪些字段。但我只想要源代碼中的字段。我寧願沒有元數據返回,因爲我不需要它,並會節省一些不必要的解析和運輸等。篩選出元數據字段,並只返回elasticsearch中的源字段
我發現Elasticsearch - how to return only data, not meta information?老問題,其中有人評論說,它不可能做到這一點。想知道這個功能是否已被添加或仍然失蹤?
我不知道在查詢中這樣的選項。這可以通過Id請求獲取。
/{index}/{type}/{id}/_source
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-get.html#_source
是的,我看到了。 – bagi
所有的REST API接受可用於 減少elasticsearch返回的響應filter_path參數。該參數採用 逗號分隔的過濾器列表以點表示法表示:
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
}
]
}
}
在蟒蛇
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獲取更多詳細信息) with filter_path paramete [R是這樣的:
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}/{類型}/_search漂亮& filter_path = take,hits.hits._id,hits.hits._score,hits.hits._source
http:// localhost:9200/{index_name}/{type} /_search?pretty&filter_path=hits.hits._source –
據我所知,這個功能_still_不存在。但是,您可以創建一個插件來執行此操作[如此處所示](https://github.com/imotov/elasticsearch-just-source/blob/master/src/main/java/org/elasticsearch/examples/justsource/休息/動作/ RestJustSourceAction.java)。 – pickypg
謝謝!想知道爲什麼ES沒有這個功能。也許只是沒有足夠的優先權。 – bagi
我想如果沒有元數據,特別是分頁,有些東西可能會變得非常困難。 – pickypg