gpt4 book ai didi

elasticsearch - Elasticsearch 仅索引可搜索字段

转载 作者:行者123 更新时间:2023-12-02 23:53:28 25 4
gpt4 key购买 nike

我想创建一个仅对某些字段建立索引的索引。我创建了一个模板,将enabled属性设置为false。因此,默认情况下没有字段被索引。
https://www.elastic.co/guide/en/elasticsearch/reference/6.4/enabled.html

然后,我定义了要使用动态模板索引的字段。插入文档后,没有索引字段。我猜这是因为enabled:false应用于根元素的子级,并且由于都不应该对其进行索引,因此不应用动态模板。

有没有办法将动态模板未涵盖的所有字段的enable设置为false?

DELETE so

DELETE _template/test

PUT _template/test
{
"index_patterns": [
"*so*"
],
"settings": {
"number_of_shards": 1
},
"mappings": {
"_doc": {
"dynamic": true,
"enabled": false,
"dynamic_templates": [
{
"typeOfMaterial": {
"path_match": "*.material.typeOfMaterial",
"mapping": {
"enabled": true,
"type": "nested"
}
}
},
{
"typeOfMaterialCode": {
"path_match": "*.material.typeOfMaterial.code",
"mapping": {
"enabled": true,
"type": "keyword"
}
}
}
]
}
}
}

PUT so/_doc/1
{
"count": 5,
"AAA": {
"material": {
"typeOfMaterial": [
{
"code": "MAT1"
}
]
}
}
}

最佳答案

根据documentation:

Templates are processed in order — the first matching template wins.



基于此假设,我将尝试修改模板,如下所示:
PUT _template/test
{
"index_patterns": [
"*so*"
],
"settings": {
"number_of_shards": 1
},
"mappings": {
"_doc": {
"dynamic": true,
"dynamic_templates": [
{
"typeOfMaterial": {
"path_match": "*.material.typeOfMaterial",
"mapping": {
"enabled": true,
"type": "nested"
}
}
},
{
"typeOfMaterialCode": {
"path_match": "*.material.typeOfMaterial.code",
"mapping": {
"enabled": true,
"type": "keyword"
}
}
},
{
"allOtherFields": {
"match": "*",
"mapping": {
"enabled": false
}
}
}
]
}
}
}

关于elasticsearch - Elasticsearch 仅索引可搜索字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55837264/

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