gpt4 book ai didi

elasticsearch - 使用其他搜索对弹性结果进行后处理(从Solr迁移)

转载 作者:行者123 更新时间:2023-12-02 23:08:50 27 4
gpt4 key购买 nike

我目前正在将应用程序从Solr迁移到Elastic,并偶然发现了我无法在Elastic中重现的有趣的Solr功能:对Solr的查询返回了对结果进行质量检查的后处理标志,指示是否在结果字段。

q  = some_field:(the brown fox)
fl = some_field, full_match:exists(query({!edismax v='some_field:(the brown fox)' mm='100%'}))

Solr结果如下所示:
{
"response": {
"docs": [
{
"some_field": "The Brown Bear",
"full_match": false
},
{
"some_field": "The Quick Brown Fox",
"full_match": true
}
]
}
}

客户端使用该标志进一步处理结果文档,而与分数无关(在示例中我省略了)。我发现这很聪明,因为使用了Solr的标记化和分布式计算功能,而不是在客户端中做任何事情。

现在,在Elastic中,我认为这应该在 script_fields块中完成,但实际上我不知道如何使用轻松的脚本执行子查询,经过两天的调查,我怀疑这是否完全可能:
{
"query": {
"match": {
"some_field": "the brown fox"
}
},
"_source": [
"some_field"
],
"script_fields": {
"full_match": {
"script": "???" <-- Search with Painless script?
}
}
}

欢迎任何创意。

最佳答案

如何将Elasticsearch的named queriesminimum_should_match参数结合使用并将其设置为100%以仅匹配所有 token 都匹配的文档?
然后,您将能够检测到响应中所有标记都匹配的查询。您还可以设置“boost”:0以避免影响主查询的分数。
这是一个示例请求:

{
"query": {
"bool": {
"should": [
{
"match": {
"message": {
"query": "the brown fox",
"_name": "main_query"
}
}
},
{
"match": {
"message": {
"query": "the brown fox",
"_name": "all_tokens_match",
"minimum_should_match": "100%",
"boost": 0
}
}
}
]
}
}
}
然后,您将获得一个类似于以下内容的响应:
{
"hits": [
{
"_score": 0.99938476,
"_source": {
"message": "The Quick Brown Fox"
},
"matched_queries": [
"main_query",
"all_tokens_match"
]
},
{
"_score": 0.38727614,
"_source": {
"message": "The Brown Bear"
},
"matched_queries": [
"main_query"
]
}
]
}
然后,查询中所有 token 都匹配的文档将在响应的 matched_queries 部分包含 all_tokens_match

关于elasticsearch - 使用其他搜索对弹性结果进行后处理(从Solr迁移),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62433645/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com