您将在搜索中获取所有三个文档,因为默认情况下,elasticsearch 使用standard analyzer 来表示text 类型字段。这会将"2021 test desc" 标记为
{
"tokens": [
{
"token": "2021",
"start_offset": 0,
"end_offset": 4,
"type": "<NUM>",
"position": 0
},
{
"token": "test",
"start_offset": 5,
"end_offset": 9,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "desc",
"start_offset": 10,
"end_offset": 14,
"type": "<ALPHANUM>",
"position": 2
}
]
}
因此,它将返回与上述任何标记匹配的所有文档。
如果您想搜索需要更新索引映射的确切术语。
您可以通过indexing the same field in multiple ways i.e by using multi fields.更新映射
PUT /_mapping
{
"properties": {
"description": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
然后再次重新索引数据。在此之后,您将能够使用文本类型的“description”字段和关键字类型的“description.raw”字段进行查询
搜索查询:
{
"query": {
"match": {
"description.raw": "test dsc"
}
}
}
搜索结果:
"hits": [
{
"_index": "67777521",
"_type": "_doc",
"_id": "2",
"_score": 0.9808291,
"_source": {
"description": "test dsc"
}
}
]