FuzzyLikeThisFieldQuery

FuzzyLikeThisFieldQuery

如何在elasticsearch中使用FuzzyLikeThisFieldQuery突出显示结果查询?我可以选择FuzzyQuery,但不能选择FuzzyLikeThisFieldQuery。例如,在下面的代码中,我使用了FuzzyQuery:

QueryBuilder allquery = QueryBuilders.fuzzyQuery("name", "fooobar").minSimilarity(0.4f);

SearchRequestBuilder builder = ds.getElasticClient()
                                        .prepareSearch("data")
                                        .setQuery(allquery)
                                        .setFrom(0)
                                        .setSize(10)
                                        .setTypes("entity")
                                        .setSearchType(SearchType.DEFAULT)
                                        .addHighlightedField("name")
                                        .addField("name");

    SearchResponse sr = builder.execute().actionGet();

结果是
If you want to have a <em>foobar</em> for oracle

但如果我使用FuzzyLikeThisFieldQuery,则不会突出显示
QueryBuilder allquery = QueryBuilders.fuzzyLikeThisFieldQuery("name").likeText("fooobar").minSimilarity(0.4f);

结果是
If you want to have a foobar for oracle

有人知道为什么吗?

最佳答案

您需要调用这两个函数来设置荧光笔标签。

builder.setHighlighterPreTags("<pre>").setHighlighterPostTags("</pre>");

关于lucene - Elasticsearch/Lucene亮点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11424927/

10-17 03:14