首页 > 解决方案 > Elasticsearch 中的完成建议程序不起作用

问题描述

(使用 ES 6.7)我有一个索引并且想要支持 search-as-you-type 功能。为此,我想尝试完成建议,但我在重新索引以更改映射旧索引时遇到了麻烦。

这是旧的索引映射

{
    "old-index": {
        "mappings": {
            "doc": {
                "properties": {
                    "content": {
                        "type": "text"
                    },
                    "project": {
                        "type": "keyword"
                    },
                    "title": {
                        "type": "text"
                    },
                    "version": {
                        "type": "keyword"
                    }
                }
            }
        }
    }
}

这是新的测试索引映射

PUT test-completion
{
    "mappings": {
        "doc": {
            "properties": {
                "content": {
                    "type": "text",
                    "fields": {
                        "autocomplete": {
                            "type": "completion",
                            "contexts": [
                                {
                                    "name": "project",
                                    "type": "category",
                                    "path": "project"
                                },
                                {
                                    "name": "version",
                                    "type": "category",
                                    "path": "version"
                                }
                            ]
                        }
                    }
                },
                "title": {
                    "type": "text"
                },
                "project": {
                    "type": "keyword"
                },
                "version": {
                    "type": "keyword"
                }
            }
        }
    }
}

这是重新索引查询

POST _reindex
{
    "source": {
        "index": "old-index"
    },
    "dest": {
        "index": "test-completion"
    }
}

这是不返回任何结果的查询

POST test-completion/_search
{
    "suggest": {
        "autocompletion_suggest": {
            "prefix": "part of documentation",
            "completion": {
                "field": "content.autocomplete",
                "fuzzy": {
                    "fuzziness": "AUTO"
                },
                "contexts": {
                    "project": "xyz-project",
                    "version": "abc-version"
                }
            }
        }
    }
}

如果前缀设置为aor b,它将返回上下文之外的结果。我在哪里做错了?

https://discuss.elastic.co/t/problem-with-completion-suggester/181695

标签: elasticsearchsearchautocompleteelasticsearch-6

解决方案


推荐阅读