当我做了
PUT /vehicles/_doc/123
{
"make" : "Honda Civic",
"color" : "Blue",
"from": "Japan",
"size": "Big",
"comment": "deja vu",
"HP" : 250,
"milage" : 24000,
"price": 19300.97
}
自动生成如下指标定义:
{
"vehicles": {
"aliases": {},
"mappings": {
"properties": {
"HP": {
"type": "long"
},
"color": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"comment": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"from": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"make": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"milage": {
"type": "long"
},
"price": {
"type": "float"
},
"size": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "1",
"provided_name": "vehicles",
"creation_date": "1670864230815",
"number_of_replicas": "1",
"uuid": "etLFicsvSXCpeuFiYCiT0g",
"version": {
"created": "8050299"
}
}
}
}
}
在索引中,比如color
,它的类型是text
,并且有一个字段keyword
,我们如何使用和查询keyword
字段?
1条答案
按热度按时间voase2hg1#
当您要查询关键字字段时,只需在查询中使用
color.keyword
,如果您只想查询text
部分,则只需在字段名称中使用color
。text
和keyword
字段以不同方式进行标记和存储,并用于不同的场景,此answer将有助于理解差异。