问题描述
有没有办法告诉 elasticsearch 不返回任何元数据?目前我可以选择要在源中返回的字段.但我只想要源中的字段.我宁愿不返回元数据,因为我不需要它,并且会节省一些不必要的解析和传输等.
我发现 Elasticsearch - 如何只返回数据,而不是元信息? 较旧的问题,有人评论说当时不可能做到这一点.想知道此功能是否已添加或仍然缺失?
所有 REST API 都接受一个 filter_path 参数,该参数可用于减少弹性搜索返回的响应.这个参数需要一个逗号分隔的过滤器列表,用点表示法表示:
curl -XGET 'localhost:9200/_search?pretty&filter_path=took,hits.hits._id,hits.hits._score'{拿":3,命中":{命中":[{"_id": "3640",_score":1.0},{"_id": "3642",_score":1.0}]}}
在蟒蛇中
def get_all( connection, index_name, type_name ):查询 = {match_all":{}}结果 = connection.search( index_name, type_name,{查询":查询},filter_path= ["took", "hits.hits._id", "hits.hits.score"])返回结果
如果你想过滤_source字段,你应该考虑结合已经存在的_source 参数(有关详细信息,请参阅获取 API)使用 filter_path 参数如下:
curl -XGET 'localhost:9200/_search?pretty&filter_path=hits.hits._source&_source=title'{命中":{命中":[{"_source":{"title":"Book #2"}}, {"_source":{"title":"Book #1"}}, {"_source":{"title":"Book #3"}]]}}
Is there a way to tell elasticsearch to not return any metadata? Currently I can select which fields I want to be returned in source. But I only want fields in source. I would prefer to not have the metadata returned as I dont need it and would save some unnecessary parsing and transport etc.
I found Elasticsearch - how to return only data, not meta information? older question where somebody commented that it wasnt possible to do it then. Wondering if this functionality has been added or is still missing?
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
}
]
}
}
In 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
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"}
} ]
}
}
这篇关于过滤掉元数据字段,只返回elasticsearch中的源字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!