如何获取与Elasticsearch中匹配的单词令牌

发布于 2025-02-09 07:43:56 字数 1226 浏览 3 评论 0原文

  • 我需要匹配的单词值列表。如果我的搜索字符串为abc,它是我的名称,我的预期列出的是值列表[abcdefabcdefgh,.. ...]

myd在

[
{'id':1,  'name': 'christiano ronaldo', 'description': 'portugal'},
{'id':2,  'name': 'lionel messi', 'description': 'argentina'},
{'id':3,  'name': 'Lionel Jr', 'description': 'brazil'}
]

DSL查询下方的MyD下方是

{
  "query": {
    "match_phrase_prefix": {
      "name": {
        "query": "lio",
        "slop": 3,
      }
    }
  }
}

我的输出下方

{'took': 2,
 'timed_out': False,
 '_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0},
 'hits': {'total': {'value': 2, 'relation': 'eq'},
  'max_score': 0.4700036,
  'hits': [{'_index': 'players',
    '_type': '_doc',
    '_id': '2',
    '_score': 0.4700036,
    '_source': {'id': 2, 'name': 'lionel messi', 'description': 'argentina'}},
   {'_index': 'players',
    '_type': '_doc',
    '_id': '3',
    '_score': 0.4700036,
    '_source': {'id': 3, 'name': 'Lionel Jr', 'description': 'brazil'}}]}}
  • ,有任何方法可以提取

像我预期的那样匹配的令牌单词,只是lionel lio 匹配LionelLionel的名称

  • I need list of values of words which matches. if my search string is abc which is theere in my name of document my expected out is just list of values [abcdef, abcdefgh, .....]

myd is below

[
{'id':1,  'name': 'christiano ronaldo', 'description': 'portugal'},
{'id':2,  'name': 'lionel messi', 'description': 'argentina'},
{'id':3,  'name': 'Lionel Jr', 'description': 'brazil'}
]

DSL query is below

{
  "query": {
    "match_phrase_prefix": {
      "name": {
        "query": "lio",
        "slop": 3,
      }
    }
  }
}

My output is below

{'took': 2,
 'timed_out': False,
 '_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0},
 'hits': {'total': {'value': 2, 'relation': 'eq'},
  'max_score': 0.4700036,
  'hits': [{'_index': 'players',
    '_type': '_doc',
    '_id': '2',
    '_score': 0.4700036,
    '_source': {'id': 2, 'name': 'lionel messi', 'description': 'argentina'}},
   {'_index': 'players',
    '_type': '_doc',
    '_id': '3',
    '_score': 0.4700036,
    '_source': {'id': 3, 'name': 'Lionel Jr', 'description': 'brazil'}}]}}
  • is there any way to extract the token word which matches

Like my expected out is only is just lionel only as lio matches the name which is lionel and Lionel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℉絮湮 2025-02-16 07:43:56

据我所知,没有直接的方法可以在搜索结果中获得文本的匹配令牌。

但是,一种方法是使用 ighlighting 文本中的匹配术语。

{
    "query": {
        "match_phrase_prefix": {
            "name": {
                "query": "lio",
                "slop": 3
            }
        }
    },
    "highlight": {
        "fields": {
            "name": {}
        }
    }
}

您可以解析搜索结果响应,并在应用程序方面检索突出显示的术语。

As far as I'm aware, there is no direct way to get only the text's matched tokens in the search result.

However, one method is to use highlighting to get the matching terms in the text.

{
    "query": {
        "match_phrase_prefix": {
            "name": {
                "query": "lio",
                "slop": 3
            }
        }
    },
    "highlight": {
        "fields": {
            "name": {}
        }
    }
}

You can parse the search result response and retrieve the highlighted terms later on the application side.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文