【问题标题】:Changing the token length of Spring Boot Elasticsearch pattern matching size更改 Spring Boot Elasticsearch 模式匹配大小的令牌长度
【发布时间】:2023-02-01 06:02:34
【问题描述】:

我正在使用 Spring Boot 和 Elasticsearch,我正在尝试使用三个字符搜索,但搜索只匹配五个或更多字符。

如果我的用户名为“Bob Smith”,我可以找到搜索“Smith”的匹配项,但搜索“Bob”时找不到匹配项。

我怀疑这是我的类“SearchMappingConfig 实现 HibernateOrmSearchMappingConfigurer”中需要更改的内容,但我找不到任何有关更改成功匹配结果所需的标记大小的信息。

我的“@Entity”表在我希望包含在令牌搜索中的字段上有“@FullTextField(analyzer = "english")”注释。

如何更改搜索匹配的长度?

理想情况下,我希望任何三个字母都能匹配,因此搜索“Ron”将匹配“Ronald”和“Laronda”

弹性搜索 7.14 春季启动 2.7.6

我一直在阅读 Spring Boot 和 Elasticsearch 文档,但找不到有关更改匹配长度的任何信息。

【问题讨论】:

    标签: spring-boot hibernate elasticsearch


    【解决方案1】:

    Hibernate 能够使用 Elasticsearch 或 Lucene 客户端。我们现有的项目使用 Lucene,要取代它是一项艰巨的任务。

    推荐的解决方案是创建新的分析器,以便传入的数据创建更小的标记,我不想更改现有数据库上的分析器。

    我能够找到的很多文档都指向使用 Elasticsearch 查询生成器或使用通配符的 Hibernate 5 方法。

    我测试了我们的 Elasticsearch,发现通配符解决方案可行。

    我最终使用 Hibernate 6 方法进行通配符搜索并且效果很好。

       SearchResult<DataClass> result = searchSession.search(DataClass.class)
                    .where(f -> f.wildcard()
                                    .fields(
                                            "firstname",
                                            "lastname",
                                            "username",
                                            "currentLegalName")
                                    .matching("*"+searchText.toLowerCase()+"*"))
                    .fetch(10);
       long totalHitCount = result.total().hitCount();
       logger.debug("Search results size {}", totalHitCount);
    

    【讨论】:

      猜你喜欢
      • 2019-05-01
      • 1970-01-01
      • 2018-05-03
      • 2013-08-19
      • 1970-01-01
      • 2019-07-25
      • 1970-01-01
      • 2013-04-09
      • 2014-05-05
      相关资源
      最近更新 更多