gpt4 book ai didi

嵌套字段的 Elasticsearch 完成建议上下文

转载 作者:行者123 更新时间:2023-11-29 02:52:24 25 4
gpt4 key购买 nike

我正在开发具有完成功能的简单搜索应用程序。我需要以某种方式确保这些建议的安全,所以我想出最简单的方法是将上下文添加到完成建议器中。我的问题是我不知道如何在嵌套字段中使用建议上下文。

这就是我的映射的样子,非常简单,只有 3 个字段和一个嵌套字段。

curl-XPUT'http: //localhost: 9200/cr/_mapping/agreement_index'-d'{
"agreement_index": {
"properties": {
"agreement_name": {
"type": "string",
"fields": {
"suggest": {
"type": "completion",
"analyzer": "simple",
"payloads": false,
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50,
"context": {
"permitted": {
"type": "category",
"path": "permitted",
"default": []
}
}
}
}
},
"permitted": {
"type": "integer"
},
"team": {
"type": "nested",
"dynamic": "false",
"properties": {
"email": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
},
"suggest": {
"type": "completion",
"analyzer": "simple",
"payloads": false,
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50,
"context": {
"permitted": {
"type": "category",
"path": "permitted",
"default": []
}
}
}
}
},
"name": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
},
"suggest": {
"type": "completion",
"analyzer": "simple",
"payloads": false,
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50,
"context": {
"permitted": {
"type": "category",
"path": "permitted",
"default": []
}
}
}
}
},
"permitted": {
"type": "integer"
}
}
}
}
}
}'

在这样的索引文档中:

curl-XPUT'http: //localhost: 9200/cr/agreement_index/1'-d'{
"agreement_name": "QWERTY",
"team": [{
"name": "Tomasz Sobkowiak",
"permitted": ["2"],
"email": "tsobkowiak@fake.com"
}],
"permitted": ["2"]
}'

我遇到以下错误:

{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"one or more prefixes needed"}],"type":"illegal_argument_exception","reason":"one or more prefixes needed"},"status":400}

从嵌套字段中的完成建议中删除上下文后,一切正常。所以我的问题是,如何在嵌套字段中使用上下文建议,路径指向外部文档中的字段?这样的事情甚至可能吗?

最佳答案

问题出在您的映射中。默认不能留空。您需要在 context suggester 的映射中至少分配一个默认值.

    "context": {
"permitted": {
"type": "category",
"path": "permitted",
"default": [] // <-- defaults can not be empty, provide at least one default integer value
}
}

The value of the default field is used, when ever no specific is provided for the certain context. Note that a context is defined by at least one value.

此外,在您尝试索引的文档中,您在 permitted 中使用 string,而它被映射为 Integer

"permitted": ["2"] // <-- change this to "permitted":[2]

关于嵌套字段的 Elasticsearch 完成建议上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35683069/

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