【问题标题】:Elasticsearch - Research that returns too many bad resultsElasticsearch - 返回太多不良结果的研究
【发布时间】:2021-07-23 17:12:32
【问题描述】:

我有一个可以工作的弹性搜索,但它真的太大了,它给了我太多与它无关的术语的结果。我正在寻找一种方法来完善这些结果。

在我搜索术语 music 时的一个假文本样本中,突出显示的术语是:
must, much, alice, inside, patriotic, noticed

我认为ngram 对我没有帮助,但我认为我确实需要它来进行更好的搜索。

这是我的配置:

{
    "number_of_shards": 1,
    "number_of_replicas": 0,
    "analysis": {
        "analyzer": {
            "default": {
                "type": "custom",
                "tokenizer": "standard",
                "filter": ["lowercase", "mySnowball", "myNgram"]
            },
            "default_search": {
                "type": "custom",
                "tokenizer": "standard",
                "filter": ["standard", "lowercase", "mySnowball", "myNgram"]
            }
        },
        "filter": {
            "mySnowball": {
                "type": "snowball",
                "language": "English"
            },
            "myNgram": {
                "type": "ngram",
                "min_gram": 2,
                "max_gram": 6
            }
        }
    }
}

这是我的要求:

    {
    "query": {
        "bool": {
            "should": [{
                "match": {
                    "content": "music"
                }
            }, {
                "match": {
                    "url": "music"
                }
            }, {
                "match": {
                    "h1": "music"
                }
            }, {
                "match": {
                    "h2": "music"
                }
            }
         ],
            "minimum_should_match": 1
        }
    },
    "min_score": 8
}

我的文档很简单:

content => text,
url => text,
h1 => text,
h2 => text,

还有映射:

$configMapping  = [
    'content' => ['type' => 'text', 'boost' => 6],
    'url'     => ['type' => 'text', 'boost' => 6],
    'h1'      => ['type' => 'text', 'boost' => 9],
    'h2'      => ['type' => 'text', 'boost' => 7]
]

我欢迎任何能让我获得一致结果的修改。

【问题讨论】:

  • 能否分享一些示例索引数据和预期的搜索结果?

标签: php elasticsearch elastica


【解决方案1】:

正如您自己所说,使用“ngram”进行分析是您获得所有这些不相关结果的原因。

在您获得的所有结果中,您可以看到与查询词“音乐”匹配的标记(2 个字符标记,作为您的 n-gram 的最小值): must, much, alice, inside, 爱国者ic,未iced

首先从您的分析器中删除此过滤器,然后继续从那里调整结果。

【讨论】:

  • 这是我为暂时消除问题所做的,我目前使用具有确切术语的搜索。下次我会更换谷歌搜索引擎^^
猜你喜欢
  • 2015-09-09
  • 1970-01-01
  • 2015-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-08
  • 1970-01-01
相关资源
最近更新 更多