V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
kimera
V2EX  ›  Elasticsearch

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

  •  
  •   kimera · 2021-07-12 10:02:06 +08:00 · 2124 次点击
    这是一个创建于 990 天前的主题,其中的信息可能已经有所发展或是发生改变。

    问题描述 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 字段,感谢

    11 条回复    2021-07-12 18:27:13 +08:00
    zhengsidao
        1
    zhengsidao  
       2021-07-12 10:07:27 +08:00
    mapping 结构展示一下
    est
        2
    est  
       2021-07-12 10:11:26 +08:00
    实在不行,索引拆了重建吧
    so1n
        3
    so1n  
       2021-07-12 10:18:34 +08:00
    其实更应该考虑该字段是否存在 es, 即使不返回数据, 它也会占用 es 的内存
    kimera
        4
    kimera  
    OP
       2021-07-12 10:29:02 +08:00
    @zhengsidao

    {
    "zdw_index_1000_199": {
    "mappings": {
    "properties": {
    "content": {
    "type": "text",
    "analyzer": "charSplit"
    },
    "content_all": {
    "type": "text",
    "analyzer": "charSplit"
    }
    }
    }
    }
    }
    weofuh
        5
    weofuh  
       2021-07-12 10:57:44 +08:00
    你这 content_all 又不是 nested 类型的,这没法过滤了吧
    ldx101214
        6
    ldx101214  
       2021-07-12 11:05:24 +08:00
    fetchSource??
    jay4497
        7
    jay4497  
       2021-07-12 11:11:08 +08:00
    抽出来做 runtime 字段试试?
    vindurriel
        8
    vindurriel  
       2021-07-12 11:45:15 +08:00 via iPhone
    有什么特殊需求必须用 content all 吗?改成 nested 虽然可以返回 但是有最大数量限制 object array 最好拆成单独的 index
    jifengg
        9
    jifengg  
       2021-07-12 13:03:24 +08:00
    "content_all": {
    "type": "text"

    array 字段被当成 string 处理了,需要改一下 mapping
    Nielsen
        10
    Nielsen  
       2021-07-12 13:25:14 +08:00 via Android
    尝试的过滤条件 "_source":{"includes":["content_all.orgWidth "],"excludes":[]} 返回记录 "_source": {} 返回内容为空了

    orgWidth 后面那个空格是你粘过来的嘛还是
    zhengsidao
        11
    zhengsidao  
       2021-07-12 18:27:13 +08:00
    这个字段类型我也不知道取得了不,你可以试试用脚本 scrip , 个人建议还是 re-index 操作
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1178 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 18:20 · PVG 02:20 · LAX 11:20 · JFK 14:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.