如何在结果中返回特定字段的标记
例如,GET请求
curl -XGET 'http://localhost:9200/twitter/tweet/1'
退货
{
"_index" : "twitter",
"_type" : "tweet",
"_id" : "1",
"_source" : {
"user" : "kimchy",
"postDate" : "2009-11-15T14:12:12",
"message" : "trying out Elastic Search"
}
}
我希望在结果中包含‘_Soure.Message’字段的标记
3条答案
按热度按时间bxfogqkk1#
还有另一种方法可以使用以下脚本_field脚本完成此操作:
重要的是要注意,虽然该脚本返回已索引的实际术语,但它也缓存所有字段值,并且在大型索引上可能会使用大量内存。因此,对于大型索引,从存储的字段或源检索字段值并使用以下MVEL脚本动态重新解析它们可能更有用:
此MVEL脚本可以存储为
config/scripts/analyze.mvel
,并与以下查询一起使用:rn0zuynd2#
如果您指的是已编制索引的令牌,则可以在消息字段中创建terms facet。增加
size
值以获取更多条目,或设置为0
以获取所有术语。Lucene提供了存储术语向量的能力,但到目前为止(据我所知)还无法通过ElasticSearch访问它。
你为什么需要这个?如果您只想检查您正在索引的内容,您可以查看analyze api。
qmelpv7a3#
如今,使用Term vectors API是可能的:
结果:
注意:Map类型(此处:tweet)已在Elasticsearch 8.x中删除(请参阅迁移指南)。