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

数据集合:

Elasticsearch查询(4)-模糊匹配和正则表达式_第1张图片

模糊查询前缀开始字符j

GET /mydb/_search

{

"query": {

"prefix": {

"name": "j"

}

}

}

模糊查询

?用来匹配1个任意字符,*用来匹配零个或者多个字符

GET /mydb/_search

{

"query": {

"wildcard": {

"postcode": "c??"

}

}

}

模糊查询

?用来匹配1个任意字符,*用来匹配零个或者多个字符

GET /mydb/_search

{

"query": {

"wildcard": {

"name.keyword": "ch??g*y*"

}

}

}

正则表达式 匹配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"

				}

			}

		]

	}
}

 

你可能感兴趣的:(elasticsearch)