在进行搜索时,Elasticsearch返回包含各种元信息的数据结构.
实际结果集包含在从数据库返回的JSON结果中的"命中"字段中.
Elasticsearch是否可以仅返回所需数据("hits"字段的内容)而不嵌入所有其他元数据中?
我知道我可以将结果解析为JSON并提取它,但我不希望复杂性,麻烦,性能受到影响.
谢谢!
以下是Elasticsearch返回的数据结构示例.
{
"_shards":{
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits":{
"total" : 1,
"hits" : [
{
"_index" : "twitter",
"_type" : "tweet",
"_id" : "1",
"_source" : {
"user" : "kimchy",
"postDate" : "2009-11-15T14:12:12",
"message" : "trying out Elastic Search"
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
Mic*_*son 19
您至少可以过滤结果,即使您无法提取它们.REST API 的" 公共选项 "页面解释了"filter_path"选项.这使您只能过滤您感兴趣的树的部分.树结构仍然相同,但没有额外的元数据.
我通常添加查询选项:
&filter_path=hits.hits.*,aggregations.*
Run Code Online (Sandbox Code Playgroud)
文档没有说明这一点,使你的查询更快(我怀疑它确实如此),但至少你只能返回有趣的部分.