kimera

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

  •  
  •   kimera · Jul 12, 2021 · 9673 views
    This topic created in 1942 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
    zhengsidao
    Jul 12, 2021
    1
    mapping 结构展示一下
    est
    est
    Jul 12, 2021
    2
    实在不行,索引拆了重建吧
    so1n
    so1n
    Jul 12, 2021
    3
    其实更应该考虑该字段是否存在 es, 即使不返回数据, 它也会占用 es 的内存
    kimera
    kimera
    OP
    Jul 12, 2021
    4
    @zhengsidao

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

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

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