5

[请教] es 搜索建议的使用实现搜索补全

 1 year ago
source link: https://www.v2ex.com/t/938796
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

[请教] es 搜索建议的使用实现搜索补全

  jiobanma · banmajio · 52 分钟前 · 147 次点击

mysql 的业务表中有 student 表和 class 表,其中 student 表中有 studentCode ,studentName 等.class 表中有 classCode ,className 等。想要实现一个功能:前端有一个输入框,根据用户输入的内容进行联想,匹配优先级为:studentCode ,studentName ,classCode ,className 。前缀匹配就好。

最开始考虑到的是使用 es 的搜索建议功能。对 es 的使用较少,怕走弯路,想请教下 v2 的大佬们,给点指点建议。

  1. 如果我把库里所有的数据同步到 es 里。索引的结构为类似为
{"field":"studentCode","value":"SN0001"},{"field":"studentName","value":"张三"},{"field":"classCode","value":"C0001"},{"field":"className","value":"韭菜班"}

这样处理是最简单的感觉。直接给 value 字段加上搜索建议,但是不知道这个怎么定优先级。不知道能实现按照指定的优先级来查询吗?还有感觉这中索引结构有些不优雅。 2. 可以通过下面这种结构实现吗?

    {
        "studentCode":"SN001",
        "studentName":"张三",
        "classCode":"C001",
        "className":"韭菜班"
    },
    {
        "studentCode":"SN001",
        "studentName":"张三",
        "classCode":"C001",
        "className":"韭菜班"
    }
  1. 或者还有其他好一点的方案吗?

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK