以位置顺序返回Elasticsearch高亮结果吗? [英] Return Elasticsearch highlight results in position order?

查看:453
本文介绍了以位置顺序返回Elasticsearch高亮结果吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用

I'm currently using the highlighting feature that elasticsearch offers in my query. However, the one thing I'm not quite clear on is about how the results are ordered. I would prefer they come back in the order that they appear in a paragraph instead of importance/score. This is so I can concatenate them with ...'s in the same order as they are in the original document (similar to Google results). However, they are currently returning in some weighted order based on best match?

有没有一种方法可以看到高亮结果而不必在现场进行额外的后处理.

Is there a way to accomplish this without having to do additional post processing on the field after seeing the highlight results.

我看到突出显示有"order" : "score"选项,但是似乎没有其他记录在案的选项可以更改退货顺序. (顺便说一句,我不理解默认顺序和计分顺序之间的区别.)

I see there is a "order" : "score" option for a highlight, but there doesn't seem to be any other documented options to change the return order. (And as an aside, I don't understand the difference between the default order and the scoring order).

这是我查询中突出显示部分的摘录.

Here's a snippet of the highlight portion of my query.

  "highlight": {
    "fields": {
      "synopsis": {
        "fragment_size": 150,
        "number_of_fragments": 4
      }
    }
  }

推荐答案

因此,在进行了一些试验之后,我发现fast-vector-highlighter将按照原始文档中出现的顺序对片段进行自然排序.为此,我需要在大纲字段映射中添加"term_vector" : "with_positions_offsets".

So after doing a bit of playing around, I discovered that the fast-vector-highlighter will natively sort the fragments in order of appearance in the original document. To enable this, I needed to add "term_vector" : "with_positions_offsets" to my synopsis field mapping.

{
  "properties" : {
    "synopsis" : {
      "type" : "string",
      "term_vector": "with_positions_offsets"
    }
  }
}

,然后按以下方式使用我的突出显示查询:

and then use my highlight query as so:

{
  "query": {
    "match": {
      "synopsis": "foo"
    }
  },
  "highlight": {
    "fields": {
      "synopsis": {
        "type": "fvh",
        "fragment_size": 150,
        "number_of_fragments": 4
      }
    }
  }
}

注意:使用"order" : "score"将导致排序遵循评分方案,而不一定遵循起始位置偏移顺序.我相信可以在

NOTE: Using "order" : "score" would cause the ordering to follow the the scoring schema, which does not necessarily follow start position offset order. I believe the exact code for this comparator can be found here, which seems to base it on the fragment's boost and then its startoffset.

这篇关于以位置顺序返回Elasticsearch高亮结果吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆