让elasticsearch只返回某些字段? [英] Make elasticsearch only return certain fields?

查看:42
本文介绍了让elasticsearch只返回某些字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 elasticsearch 来索引我的文档.

I'm using elasticsearch to index my documents.

是否可以指示它只返回特定字段而不是它存储的整个 json 文档?

Is it possible to instruct it to only return particular fields instead of the entire json document it has stored?

推荐答案

是的,使用更好的选择 源过滤器.如果您使用 JSON 进行搜索,它将如下所示:

Yep, Use a better option source filter. If you're searching with JSON it'll look something like this:

{
    "_source": ["user", "message", ...],
    "query": ...,
    "size": ...
}

在 ES 2.4 及更早版本中,您还可以使用 搜索 API 的字段选项:

In ES 2.4 and earlier, you could also use the fields option to the search API:

{
    "fields": ["user", "message", ...],
    "query": ...,
    "size": ...
}

这在 ES 5+ 中已被弃用.无论如何,源过滤器更强大!

This is deprecated in ES 5+. And source filters are more powerful anyway!

这篇关于让elasticsearch只返回某些字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆