数据准备
//创建索引 PUT my_index { "mappings": { "my_type": { "properties": { "title": { "type": "keyword" } } } } }
//新增数据 POST my_index/my_type { "title":"C4I8-UI365" } POST my_index/my_type { "title":"C3K5-DFG65" } POST my_index/my_type { "title":"C4I8-UI365" }
//前缀搜索 GET my_index/my_type/_search { "query": { "prefix": { "title": { "value": "C3" } } } } //通配符搜索 GET my_index/my_type/_search { "query": { "wildcard": { "title": { "value": "C5" } } } } //正则搜索 GET my_index/my_type/_search { "query": { "regexp": { "title": { "value": "C[0-9].+" } } } }
注意:
1.以上三种搜索性能都很低,会扫描所有的倒排索引才会结束
2.前缀越短,要处理的doc越多,性能越差,尽可能用长前缀搜索