使弹性搜索只返回某些字段? [英] Make elasticsearch only return certain fields?
本文介绍了使弹性搜索只返回某些字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以指示它只返回特定字段而不是其存储的整个json文档?
解决方案
是的!使用源过滤器。如果您正在使用JSON进行搜索,则会显示如下:
{
_source:[用户,消息,...],
查询:...,
大小:...
}
在ES 2.4及更早版本中,您还可以使用搜索API中的域选项:
{
fields:[user,message,...],
query:...,
size:...
}
这在ES 5+中已被弃用。源代码过滤器更强大!
I'm using elasticsearch to index my documents.
Is it possible to instruct it to only return particular fields instead of the entire json document it has stored?
解决方案
Yep! Use a source filter. If you're searching with JSON it'll look something like this:
{
"_source": ["user", "message", ...],
"query": ...,
"size": ...
}
In ES 2.4 and earlier, you could also use the fields option to the search API:
{
"fields": ["user", "message", ...],
"query": ...,
"size": ...
}
This is deprecated in ES 5+. And source filters are more powerful anyway!
这篇关于使弹性搜索只返回某些字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文