• 请不要在回答技术问题时复制粘贴 AI 生成的内容
lslvxy
V2EX  ›  程序员

咨询一个 ES 的问题

  •  
  •   lslvxy · Jun 20, 2022 · 3001 views
    This topic created in 1448 days ago, the information mentioned may be changed or developed.

    一个业务系统之前用的是 ES6.x 的,查询里的 filter 写的是

    {
      terms:{
        eventName:[
        "xxx"
        ]
      }
    }
    

    然后换了个 ES7.x 的版本 这个查询就查不到数据了 要改成

    {
      terms:{
        eventName.keyword:[
        "xxx"
        ]
      }
    }
    

    eventName 要改成 eventName.keyword 才有数据 请问这个查询怎么兼容,我翻了一下 es 的更新日志也没有发现相关的变更项

    11 replies    2022-06-20 12:19:22 +08:00
    Oktfolio
        1
    Oktfolio  
       Jun 20, 2022
    text 类型没法精确匹配
    sujin190
        2
    sujin190  
       Jun 20, 2022
    ES7.x 和 ES6.x 的数据结构不一样,想要一样,需要调整 es mapping 的配置吧
    DonaldY
        3
    DonaldY  
       Jun 20, 2022
    term 用于 keyword 。
    zzl22100048
        4
    zzl22100048  
       Jun 20, 2022
    你们迁移数据的时候没有配置索引指定字段类型,es 动态 mapping ,string 是 text 类型,加上一个 keyword 的 field
    zitionguo
        5
    zitionguo  
       Jun 20, 2022   ❤️ 1
    重建索引吧,mapping 里边 eventName 由 text -> keyword
    misaka19000
        6
    misaka19000  
       Jun 20, 2022
    看 mapping
    Morriaty
        7
    Morriaty  
       Jun 20, 2022
    这个和 es version 没关系,可以看下 https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html ,写的是 es 2.0 ,但道理一样
    decken
        8
    decken  
       Jun 20, 2022
    感觉是换了版本之后 mapping 改了 贴上 2 次的 mapping 吧
    Red998
        9
    Red998  
       Jun 20, 2022
    matchQuery:会将搜索词分词,再与目标查询字段进行匹配,若分词中的任意一个词与目标字段匹配上,则可查询到。

    termQuery:不会对搜索词进行分词处理,而是作为一个整体与目标字段进行匹配,若完全匹配,则可查询到。
    zmal
        10
    zmal  
       Jun 20, 2022   ❤️ 1
    可能你用的是 ES 自动生成的 mapping ,没有自定义。无需分词的字符串字段改成 keyword 。
    sadfQED2
        11
    sadfQED2  
       Jun 20, 2022 via Android
    目测你没有给这个字段加 keyword 类型的 field ,直接贴你的 mapping 上来吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   947 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 101ms · UTC 18:29 · PVG 02:29 · LAX 11:29 · JFK 14:29
    ♥ Do have faith in what you're doing.