es既想包含查询,又想精确查询

来源:互联网 发布:笨马网络 编辑:程序博客网 时间:2024/05/18 03:02

1.如果es既想包含查询(即类似数据库like)又想精确查询(完全相等,类似于数据库=),则只要建立mapping中如下设置即可。查包含时直接字段名,=查询时加.raw.


PUT /my_index/_mapping/blogpost{  "properties": {    "user": {      "properties": {        "name": {           "type": "string",          "fields": {            "raw": {               "type":  "string",              "index": "not_analyzed"            }          }        }      }    }  }}

即就是一般字段type下面加

 "fields": {            "raw": {               "type":  "string",              "index": "not_analyzed"            }          }

2.以上未设置分析器还能进行包含查询,是因为若未配置的话,es默认为标准分析器,按unicode分析,支持世界所有语言,只是支持得不够友好。

原创粉丝点击