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

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

问题描述

在我的数据集中,文档包含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)

推荐答案

我想你在寻找

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


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

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

字段将自动加载存储字段(存储映射设置为
yes ),或者如果不存储,将加载 _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).

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

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