我可以在 elasticsearch 查询中指定结果字段吗? [英] Can I specify the result fields in elasticsearch query?
问题描述
在我的数据集中,一个文档包含 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屋!