简体   繁体   English

控制Elasticsearch高亮结果中的窗口大小

[英]Control the window size in elasticsearch highlight results

I'm looking for a way to extract the results of the span_near hit from elasticsearch. 我正在寻找一种从span_near提取span_near命中结果的方法。 Ultimately, I would like to extract the phrase along with a couple of tokens to the left and to the right of the span terms. 最终,我想提取该短语以及跨度术语左侧和右侧的几个标记。 I learnt about highlighters and thought they are the way to go. 我了解了荧光笔,并认为它们是必经之路。

Say this is my query: 说这是我的查询:

GET morf_texts/_search
{
  "query": {
    "span_near": {
      "clauses": [
        {
          "span_term": {
            "content": {
              "value": "estetyczny"
            }
          }
        },
        {
          "span_term": {
            "content": {
              "value": "zachowanie"
            }
          }
        }
      ],
      "slop": 3,
      "in_order": false
    }
  },
  "highlight": {"fields": {"content": {}}}
}

The result hits are listed like this: 结果匹配如下所示:

"hits": {
    "total": 1,
    "max_score": 1.672149,
    "hits": [
      {
        "_index": "morf_texts",
        "_type": "doc",
        "_id": "1",
        "_score": 1.672149,
        "_source": {
          "content": """
Piękno – pozytywna właściwość estetyczna bytu wynikająca z zachowania proporcji, harmonii barw, dźwięków, stosowności, umiaru i użyteczności, odbierana przez zmysły. Istnieje piękno idealne, duchowe, moralne, naturalne, cielesne, obiektywne i subiektywne. Pojęcie to jest silnie związane z teorią estetyki, prawdy i dobra.
W metafizyce, piękno jest jedną z transcendentalnych właściwości bytu, wyrażającą jego scalenie, przejrzystość, proporcję wewnętrzną tworzyw bytu oraz doskonałość.
Badaniami nad precyzowaniem terminu piękna zajmują się nie tylko filozofowie i artyści, lecz także teoretycy z dziedzin: historii i krytyki sztuki, antropologii, socjologii, psychologii, a także szkolnictwa.
"""
        },
        "highlight": {
          "content": [
            "Piękno – pozytywna właściwość <em>estetyczna</em> bytu wynikająca z <em>zachowania</em> proporcji, harmonii barw, dźwięków"
          ]
        }
      }
    ]

This is already great because I get three tokens to the left of estetyczna and four to the right of zachowania . 因为我得到三个令牌的左边这已经是很大的estetyczna和四权zachowania Is there a way to control how many tokens to the left and right it will highlight? 有没有一种方法可以控制将突出显示左侧和右侧的令牌数量?

So, after looking for a solution for some time, I think there's no way to control the number of tokens to the left or right. 因此,在寻找解决方案一段时间后,我认为无法控制左侧或右侧的令牌数量。

What can be controlled, though, is the number of characters each fetched fragment contains. 但是,可以控制的是每个提取的片段包含的字符数。 If the number of characters is big enough, then the fragment should hopefully have enough context to the left and to the right to fulfill the token count requirement. 如果字符数足够大,则该片段希望在左右两侧具有足够的上下文,以满足令牌计数要求。

An example of query using fragment_size parameter would look like this: 使用fragment_size参数进行查询的示例如下所示:

GET morf_texts/_search
{
  "query": {
      ...
  },
  "highlight": {
    "fields": {
      "content": {
        "fragment_size": 200
      }
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM