gpt4 book ai didi

dynamic - 为嵌套文档定义动态 not_analyzed 字段

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

我有一个如下所示的文档,“tags”字段是一个嵌套文档,我想将标签文档的所有子字段设置为index = not_analyzed。问题是标签中的字段是动态的。任何标签都可能。那么我如何为此定义动态映射。

{
strong text'level': 'info',
'tags': {
'content': u'Nov 6 11:07:10 ja10 Keepalived_healthcheckers: Adding service [172.16.08.105:80] to VS [172.16.1.21:80]',
'id': 1755360087,
'kid': '2012121316',
'mailto': 'yanping3,chunying,pengjie',
'route': 15,
'service': 'LVS',
'subject': 'LVS_RS',
'upgrade': 'no upgrade configuration for this alert'
},
'timestamp': 1383707282.500464
}

最佳答案

我认为你可以使用dynamic templates为了这。例如,以下 shell 脚本使用在索引字段 tags.* 时设置的 dynamic template 创建 dynamic_mapping_test 索引,映射设置为 type:string index:not_analyzed

echo "Delete dynamic_mapping_test"
curl -s -X DELETE http://localhost:9200/dynamic_mapping_test?pretty ; echo ""

echo "Create dynamic_mapping_test with nested tags and dynamic_template"
curl -s -X POST http://localhost:9200/dynamic_mapping_test?pretty -d '{
"mappings": {
"document": {
"dynamic_templates": [
{
"string_template": {
"path_match": "tags.*",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
],
"properties": {
"tags": {
"type": "nested"
}
}
}
}
}' ; echo ""


echo "Display mapping"
curl -s "http://localhost:9200/dynamic_mapping_test/_mapping?pretty" ; echo ""

echo "Index document with new property tags.content"
curl -s -X POST "http://localhost:9200/dynamic_mapping_test/document?pretty" -d '{
"tags": {
"content": "this CONTENT should not be analyzed"
}
}' ; echo ""

echo "Refresh index"
curl -s -X POST "http://localhost:9200/dynamic_mapping_test/_refresh"

echo "Display mapping again"
curl -s "http://localhost:9200/dynamic_mapping_test/_mapping?pretty" ; echo ""

echo "Index document with new property tags.title"
curl -s -X POST "http://localhost:9200/dynamic_mapping_test/document?pretty" -d '{
"tags": {
"title": "this TITLE should not be analyzed"
}
}' ; echo ""

echo "Refresh index"
curl -s -X POST "http://localhost:9200/dynamic_mapping_test/_refresh"; echo ""

echo "Display mapping again"
curl -s "http://localhost:9200/dynamic_mapping_test/_mapping?pretty" ; echo ""

关于dynamic - 为嵌套文档定义动态 not_analyzed 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19920279/

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