gpt4 book ai didi

python - 在 Elasticsearch 中的某些字段上禁用搜索

转载 作者:行者123 更新时间:2023-12-02 22:34:19 25 4
gpt4 key购买 nike

我只想在一个字段“XYZ”中搜索。我正在使用下面的代码,但这给了我错误。你能帮我吗?

{
"dynamic": "false",
"properties": {
"ABC": {
"type": "text",
"index": false,
"store": true

},
"PQR": {
"type": "text",
"index": false,
"store": true
},
"XYZ": {
"type": "text"
}
}
}
附言我希望将字段“ABC”和“PQR”存储在 flex 搜索中,但我也想禁用对这些字段的搜索。

最佳答案

您可以使用enabled mapping parameter

The enabled setting, which can be applied only to the top-levelmapping definition and to object fields, causes Elasticsearch to skipparsing of the contents of the field entirely. The JSON can still beretrieved from the _source field, but it is not searchable or storedin any other way:


索引映射:
{
"mappings": {
"properties": {
"ABC": {
"enabled":false
},
"PQR": {
"enabled":false
},
"XYZ": {
"type": "text"
}
}
}
}
索引数据:
{
"ABC": "b",
"PQR": "c",
"XYZ": "a"
}
搜索查询:
PQR字段上搜索时,没有搜索结果。
{
"query": {
"match": {
"PQR": {
"query": "c"
}
}
}
}
搜索结果:
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": []
}
搜索查询:
{
"query": {
"match": {
"XYZ": {
"query": "a"
}
}
}
}
搜索结果:
"hits": [
{
"_index": "stof_64113718",
"_type": "_doc",
"_id": "1",
"_score": 0.13353139,
"_source": {
"ABC": "b",
"PQR": "c",
"XYZ": "a"
}
}
]

关于python - 在 Elasticsearch 中的某些字段上禁用搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64113718/

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