Elasticsearch查询4(模糊匹配和正则表达式)

数据集合如下:
Elasticsearch查询4(模糊匹配和正则表达式)
 //模糊查询 前缀查询开始字符 j
GET /mydb/_search
{
"query": {
"prefix": {
"name": "j"
}
}
}

"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "mydb",
"_type": "external",
"_id": "1",
"_score": 1,
"_source": {
"name": "jack",
"age": 31,
"date": "2018-04-12 12:01:01"
}
},
{
"_index": "mydb",
"_type": "external",
"_id": "Xp43w2IBJNOIwaI4TryI",
"_score": 1,
"_source": {
"name": "jack",
"age": 28,
"date": "2018-04-11 13:01:01"
}
}
]
}

//模糊查询
//?用来匹配1个任意字符,*用来匹配零个或者多个字符
GET /mydb/_search
{
"query": {
"wildcard": {
"postcode": "c??"
}
}
}

//查询结果
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "mydb",
"_type": "external",
"_id": "X543w2IBJNOIwaI4YLwQ",
"_score": 1,
"_source": {
"name": "chy",
"age": 28,
"date": "2018-04-11 13:01:01"
}
}
]
}

//模糊查询
//?用来匹配1个任意字符,*用来匹配零个或者多个字符
GET /mydb/_search
{
"query": {
"wildcard": {
"name.keyword": "ch??g*y*"
}
}
}

//查询结果
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "mydb",
"_type": "external",
"_id": "Yp47w2IBJNOIwaI407zN",
"_score": 1,
"_source": {
"name": "cheng hong yan",
"age": 28,
"date": "2018-04-11 13:01:01"
}
},
{
"_index": "mydb",
"_type": "external",
"_id": "YJ43w2IBJNOIwaI4ibx3",
"_score": 1,
"_source": {
"name": "chenghongyan",
"age": 28,
"date": "2018-04-11 13:01:01"
}
}
]
}

//正则表达式 匹配c后面2个任意字符
GET /mydb/_search
{
"query": {
"regexp": {
"name.keyword": "c[a-z]{1,2}"
}
}
}

//查询结果
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "mydb",
"_type": "external",
"_id": "X543w2IBJNOIwaI4YLwQ",
"_score": 1,
"_source": {
"name": "chy",
"age": 28,
"date": "2018-04-11 13:01:01"
}
}
]
}