请教下 Elasticsearch 如何过滤只返回数组的某些字段

2021 年 7 月 12 日
 kimera

问题描述 es 返回的字段过大,需要把没有使用的多余字段过滤掉

详细描述 es 存储结构 { "content_all": [{ "orgWidth":100, "orgHeight":200, "column3":"非常大的字段" }, { "orgWidth":100, "orgHeight":200, "column3":"非常大的字段" },{ "orgWidth":100, "orgHeight":200, "column3":"非常大的字段" },{ "orgWidth":100, "orgHeight":200, "column3":"非常大的字段" } ] }

由于 column3 字段很大,返回时间过长;需要只返回 content_all.orgWidth 和 content_all.orgHeight 字段

尝试的过滤条件 "_source":{"includes":["content_all.orgWidth "],"excludes":[]} 返回记录 "_source": {} 返回内容为空了

请问下如何才能实现只返回 content_all.orgWidth 和 content_all.orgHeight 字段,感谢

3010 次点击
所在节点    Elasticsearch
11 条回复
zhengsidao
2021 年 7 月 12 日
mapping 结构展示一下
est
2021 年 7 月 12 日
实在不行,索引拆了重建吧
so1n
2021 年 7 月 12 日
其实更应该考虑该字段是否存在 es, 即使不返回数据, 它也会占用 es 的内存
kimera
2021 年 7 月 12 日
@zhengsidao

{
"zdw_index_1000_199": {
"mappings": {
"properties": {
"content": {
"type": "text",
"analyzer": "charSplit"
},
"content_all": {
"type": "text",
"analyzer": "charSplit"
}
}
}
}
}
weofuh
2021 年 7 月 12 日
你这 content_all 又不是 nested 类型的,这没法过滤了吧
ldx101214
2021 年 7 月 12 日
fetchSource??
jay4497
2021 年 7 月 12 日
抽出来做 runtime 字段试试?
vindurriel
2021 年 7 月 12 日
有什么特殊需求必须用 content all 吗?改成 nested 虽然可以返回 但是有最大数量限制 object array 最好拆成单独的 index
jifengg
2021 年 7 月 12 日
"content_all": {
"type": "text"

array 字段被当成 string 处理了,需要改一下 mapping
Nielsen
2021 年 7 月 12 日
尝试的过滤条件 "_source":{"includes":["content_all.orgWidth "],"excludes":[]} 返回记录 "_source": {} 返回内容为空了

orgWidth 后面那个空格是你粘过来的嘛还是
zhengsidao
2021 年 7 月 12 日
这个字段类型我也不知道取得了不,你可以试试用脚本 scrip , 个人建议还是 re-index 操作

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/788938

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX