Dynamic 为嵌套文档定义动态未分析字段
我有一个像下面这样的文档,“tags”字段是一个嵌套文档,我想让tags文档的所有子字段都成为index=not_analysis。问题是标记中的字段将是动态的。任何标签都有可能。 因此,我如何为这个定义动态映射Dynamic 为嵌套文档定义动态未分析字段,dynamic,mapping,elasticsearch,Dynamic,Mapping,elasticsearch,我有一个像下面这样的文档,“tags”字段是一个嵌套文档,我想让tags文档的所有子字段都成为index=not_analysis。问题是标记中的字段将是动态的。任何标签都有可能。 因此,我如何为这个定义动态映射 { strong text'level': 'info', 'tags': { 'content': u'Nov 6 11:07:10 ja10 Keepalived_healthcheckers: Adding service [172.16.08.105:80] to V
{
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
}
我认为在索引数据时没有任何方法可以指定映射。因此,作为替代方案,您可以修改标记文档,使其具有以下映射:
{ tags: {
properties: {
tag_type: {type: 'string', index: 'not_analyzed'}
tag_value: {type: 'string', index: 'not_analyzed'}
}
}
}
这里,tag\u type
可以包含任何值(content
,id
,kid
,mailto
,等等),tag\u值
可以包含在tag\u type中命名的字段的实际值 我想你可以用这个。例如,下面的shell脚本在索引字段标记时使用动态模板设置创建动态映射测试索引。*
,映射设置为类型:string
和索引:未分析
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 ""
我建议,所有字符串都是“未分析的”,所有数字都是long和“未分析的”
因为分析的默认字符串具有更多内存和文件大小
我缩小了搜索字段的大小,搜索字段的全字
范围搜索长类型
{
"mappings": {
"_default_": {
"_source": {
"enabled": true
},
"_all": {
"enabled": false
},
"_type": {
"index": "no",
"store": false
},
"dynamic_templates": [
{
"el": {
"match": "*",
"match_mapping_type": "long",
"mapping": {
"type": "long",
"index": "not_analyzed"
}
}
},
{
"es": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
}
}
我认为使用Thnx是可能的,我知道:)您不需要“el”
动态模板<代码>“索引”:“未分析”
。如果要将类型从long
更改为integer
,作为优化步骤,则可能需要更改