【问题标题】:Elastic Search with Searckiq Incorrect Scoring带有 Searckiq 不正确评分的弹性搜索
【发布时间】:2021-11-19 09:09:49
【问题描述】:

我有一个模型 Grave,我想在其中查询名称,查询为“Krogness”

我注意到一件事,返回的结果具有相同的分数。 如文档中所述,我将分片数量减少到 1(不走运)。 我什至禁用了拼写错误(运气不好)

下面附上详细的映射和说明。

型号

searchkick word_middle: %i[name plot_number], callbacks: :async, settings: {number_of_shards: 1}

模型 Searchkick 选项

{:word_middle=>[:name, :plot_number],
:callbacks=>:async,
:settings=>{:number_of_shards=>1},
:_type=>
#<Proc:0x00007f53349fcf98@/home/akshayparekh/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/bundler/gems/searchkick-bcd6edc872f2/lib/searchkick/model.rb:17 (lambda)>,
:class_name=>"Grave"}

搜索选项

{:fields=>["name^10", "plot_number"],
:where=>{:grave_status=>[:accepted, :claimed], :hidden=>false},
:operator=>:or,
:page=>"1",
:per_page=>30,
:misspellings=>false,
:debug=>true}

查询

curl http://localhost:9200/graves_development/_search?pretty -H 'Content-Type: application/json' -d '{"query":{"bool":{"must":{"bool":{"should":[{"dis_max":{"queries":[{"match":{"name.analyzed":{"query":"Krogness","boost":100.0,"operator":"or","analyzer":"searchkick_search"}}},{"match":{"name.analyzed":{"query":"Krogness","boost":100.0,"operator":"or","analyzer":"searchkick_search2"}}}]}},{"dis_max":{"queries":[{"match":{"plot_number.analyzed":{"query":"Krogness","boost":10,"operator":"or","analyzer":"searchkick_search"}}},{"match":{"plot_number.analyzed":{"query":"Krogness","boost":10,"operator":"or","analyzer":"searchkick_search2"}}}]}}]}},"filter":[{"terms":{"grave_status":["accepted","claimed"]}},{"term":{"hidden":{"value":false}}}]}},"timeout":"11s","_source":false,"size":30}'

结果

{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 1275.969,
"hits": [
{
"_index": "graves_development_20210926173013383",
"_type": "_doc",
"_id": "264729",
"_score": 1275.969
},
{
"_index": "graves_development_20210926173013383",
"_type": "_doc",
"_id": "264730",
"_score": 1275.969
}
]
}
}

我有 2 条记录可以重现此问题。

Test Krogness
Test Krog

当我搜索 Krogness 时,它们的分数相同

Searchkick 版本:4.6.1 Elasticsearch 版本:7.14.1

非常感谢任何帮助

【问题讨论】:

    标签: ruby-on-rails elasticsearch searchkick


    【解决方案1】:

    通常情况下,名称​​不 是有意义的(并且不应完全返回“Krog”)。如果你真的需要它们,你应该在你的 ES 映射中有这样的子字段:

    "name": {
      "type": "text",
      "fields": {
        "analyzed": {"type": "text", "analyzer": "searchkick_word_middle_index"},
        "lowercase": {"type": "text", "analyzer": "standard"},
        "raw": {"type": "keyword"},
      }
    }
    

    然后在搜索阶段,您将拥有:

    ["name.raw^100", "name.lowercase^50", "name.analyzed^100", ...]
    

    这样,“更精确”的匹配得分会更高。

    要让 searchkick 为你应用这些映射,你需要这样的东西:

    searchkick merge_mappings: true, mappings: {{
      properties: {
        name: {
          type: "text"
          fields: {...}
        }
      }
    }
    

    【讨论】:

    • 我尝试了上述步骤,现在它根本没有获取任何与 Krogness 相关的记录。它获取像 Krogdal 这样的记录
    • 我不确定 searchkick 默认使用哪个分析器。您可以尝试获取默认配置的映射 (curl http://localhost:9200/graves_development/_mapping)(代码中没有自定义映射)并用它替换“searchkick_word_middle_index”。如果它仍然不起作用,请在此处发布映射。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 2019-05-18
    • 1970-01-01
    相关资源
    最近更新 更多