【问题标题】:Elasticsearch in Java: SearchHit fragments get shortenedJava 中的 Elasticsearch:SearchHit 片段被缩短
【发布时间】:2017-03-13 12:55:45
【问题描述】:

我使用已经是 Elasticsearch 一部分的突出显示。它工作正常。例如,如果我有下一个“单词”索引:

  1. isweryweeylongf 的非常长的工作
  2. tes!tr%31=!"$:_ae 测试!"daca214xx

如果我搜索 -> that 。结果如下 -> verylongwork that isweryweeylongf 。包括加粗部分。 但如果我搜索 -> test 。结果是 -> $:_ae test !" .

因此片段被分割/缩短。

这可能与特殊字符有关。搜索时,我使用 QueryParser.escape() 来逃避它们。

可能是什么问题?

编辑: 另外,如果我搜索 tes,结果将是两个片段 -> tes!tr 和 $:_ae test !"

【问题讨论】:

    标签: java elasticsearch highlighting elasticsearch-2.0


    【解决方案1】:

    所以看起来“问题”是我设置了默认的片段数(5)。就我而言,这是没有意义的,因为我正在寻找较短的字符串。 所以解决方案是:

     final HighlightBuilder.Field field = new HighlightBuilder.Field(fieldToHighlight.getName());
            field.preTags("<strong>");
            field.postTags("</strong>");
            field.numOfFragments(0);
    

    只需将 numOfFragments 设置为 0 即可。

    【讨论】:

      猜你喜欢
      • 2015-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-06
      • 1970-01-01
      • 1970-01-01
      • 2018-04-17
      • 1970-01-01
      相关资源
      最近更新 更多