V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
kimera

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

  •  
  •   kimera · Jul 12, 2021 · 5256 views
    This topic created in 1760 days ago, the information mentioned may be changed or developed.

    问题描述 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 replies    2021-07-12 18:27:13 +08:00
    zhengsidao
        1
    zhengsidao  
       Jul 12, 2021
    mapping 结构展示一下
    est
        2
    est  
       Jul 12, 2021
    实在不行,索引拆了重建吧
    so1n
        3
    so1n  
       Jul 12, 2021
    其实更应该考虑该字段是否存在 es, 即使不返回数据, 它也会占用 es 的内存
    kimera
        4
    kimera  
    OP
       Jul 12, 2021
    @zhengsidao

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

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

    orgWidth 后面那个空格是你粘过来的嘛还是
    zhengsidao
        11
    zhengsidao  
       Jul 12, 2021
    这个字段类型我也不知道取得了不,你可以试试用脚本 scrip , 个人建议还是 re-index 操作
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4595 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 05:34 · PVG 13:34 · LAX 22:34 · JFK 01:34
    ♥ Do have faith in what you're doing.