{"mappings": {"properties": {"name": {"type": "text", // 主字段,用于全文搜索"fields": {"keyword": { // 子字段名"type": "keyword", // 子字段,用于精确匹配"ignore_above": 256}}}}} }
1.
◦
2.
◦
GET dev_companies/_search {"query": {"match": {"name": "Dragon Ball"}} }
- 精确匹配: 采用子字段
name.keyword
(类型为keyword
),用于匹配未分词的值:
GET dev_companies/_search {"query": {"term": {"name.keyword": "Dragon Ball Co., Ltd."}} }
- 短语应匹配: 如果需要匹配分词序列,使用
match_phrase
及远离参数slop
:
GET dev_companies/_search
{"query": {"match_phrase": {"name": {"query": "Dragon Ball","slop": 2}}}
}