1. 新建一个索引,索引名为account
PUT account { }
2. 创建索引映射文件
其中text类型,es会自动分词,另外添加一个属性字段keyword,保存原来不分词的字段
PUT account/_mapping { "properties": { "account_name": { "type": "text", "analyzer": "ik_smart", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }
3. 添加一条记录doc,并且设置id
PUT account/_doc/1 { "account_name": "程序员的早餐" }
PUT account/_doc/4 { "account_name": "早餐的程序员" }
4. 查询记录
GET account/_search { "query": { "bool": { "should": [ { "match": { "account_name.keyword": "早餐的程序员" } }, { "match": { "account_name": "早餐的程序员" } } ] } } }