我可以在 elasticsearch 查询中指定结果字段吗? [英] Can I specify the result fields in elasticsearch query?

查看:47
本文介绍了我可以在 elasticsearch 查询中指定结果字段吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据集中,一个文档包含 20 多个带有嵌套对象的字段.其中大部分是长文本字段.这些字段对于全文搜索很重要,但我们只需要在输出中显示标题、简短描述和 Id.

In my dataset, a document contains 20+ fields with nested objects. Most of them are long text fields. These fields are important for full-text search but we only need to show the title, short-description and Id in output.

是否可以在 ElasticSearch 中为全文查询指定输出字段?(如MongoDB中的投影)

Is it possible to specify the output fields in ElasticSearch for a full text query? (like projection in MongoDB)

推荐答案

我认为您正在寻找 fields 搜索请求的属性:

I think you're looking for the fields property of a search request:

允许有选择地加载每个文档的特定字段由搜索命中表示.默认加载内部 _source领域.

Allows to selectively load specific fields for each document represented by a search hit. Defaults to load the internal _source field.

{
    "fields" : ["user", "postDate"],
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

字段将自动加载存储的字段(存储映射设置为是),或者,如果没有存储,将加载 _source 并从中提取它(允许返回嵌套的文档对象).

The fields will automatically load stored fields (store mapping set to yes), or, if not stored, will load the _source and extract it from it (allowing to return nested document object).

这篇关于我可以在 elasticsearch 查询中指定结果字段吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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