对令牌的Elasticsearch匹配查询返回的相关结果较少

时间:2019-01-04 12:39:50

标签: elasticsearch search token

您好,有人可以帮助我了解Elasticsearch如何评估令牌的相关性吗?我有一个字段 nn ,其映射类似于

{
    "settings": {
        "index": {
            "refresh_interval": "-1",
            "number_of_shards": "4",
            "analysis": {
                "filter": {
                    "stopwords_SK": {
                        "ignore_case": "true",
                        "type": "stop",
                        "stopwords_path": "stopwords/slovak.txt"
                    },
                    "autocomplete_filter": {
                        "type": "edge_ngram",
                        "min_gram": "2",
                        "max_gram": "20"
                    }
                },
                "analyzer": {
                    "autocomplete": {
                        "filter": [
                            "stopwords_SK",
                            "lowercase",
                            "stopwords_SK",
                            "autocomplete_filter"
                        ],
                        "type": "custom",
                        "tokenizer": "standard"
                    }
                }
            },
            "number_of_replicas": "1"
        }
    },
    "mappings": {
        "doc": {
            "dynamic": "strict",
            "properties": {
                "nn": {
                    "type": "text",
                    "fielddata": true,
                    "fields": {
                        "raw": {
                            "type": "keyword"
                        }
                    },
                    "boost": 10,
                    "analyzer": "autocomplete"
                }
            }
        }
    }
} 

通过标准标记生成器对nn字段进行了标记。接下来的简单查询效果很好,并返回相关结果,例如“ softone sro”,“ softec sro” ...

{
    "_source": [
        "nn", 
        "nazov"
    ],
    "size": 10,
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "nn": "softo"
                    }
                }
            ]
        }
    }
}

但是,如果我需要在查询中添加应该条件,它绝对不会返回任何相关结果,并且会丢失先前最相关的内容,例如“ sofone”或“ softex”。它返回例如“ zo soz kovo zts nova as zts elektronika as ”或“ agentura socialnych sluzieb ass no ” ... 这是应查询

{
    "_source": [
        "nn",
        "nazov"
    ],
    "size": 10,
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "nn": "softo"
                    }
                }
            ],
            "should": [
                {
                    "match": {
                        "nn": "as"
                    }
                },
                {
                    "match": {
                        "nn": "sro"
                    }
                }
            ]
        }
    }
}

为什么应查询结果中缺少与第一次查询最相关的“ sofone”和“ softex”项?尽管相关性是基于令牌长度的,但这意味着“ sotf”令牌比“ so”令牌更相关。 谢谢。

0 个答案:

没有答案