目录
range范围查询
"range":{
"@timestamp":{
"gte":"2021-05-25T02:34:01.784Z",
"lte":"2021-05-27T02:34:01.784Z"
}
}
exists字段是否存在
{
"exists": {
"field": "path"
}
}
filter过滤
{
"filter":[
{"term":
{"price":40}
}
]
}
match查询
match查询会先对搜索词进行分词,分词完毕后再逐个对分词结果进行匹配,,因此相比于term的精确搜索,match是分词匹配搜索,match搜索还有两个相似功能的变种,一个是match_phrase,一个是multi_match。
match
match因为字符串是按照空格分词,因此分为request和submissionContext两个单词。只要文本包含其中两个单词就会被命中
{
"query": {
"match": {
"content": "request submissionContext"
}
}
}
match_phrase
match_phrase为按短语搜索,会把字符串整体作为一个词搜索。
{
"query": {
"match_phrase": {
"content": "request submissionContext"
}
}
}
multi_match
multi_match 查询为能在多个字段上反复执行相同查询提供了一种便捷方式。
{
"multi_match": {
"query": "Quick brown fox",
"type": "best_fields",
"fields": [ "title", "body" ],
"tie_breaker": 0.3,
"minimum_should_match": "30%"
}
}
{
"multi_match": {
"query": "Quick brown fox",
"fields": "*_title"
}
}
prefix前缀搜索(不常用)
{
"query": {
"prefix": {
"fieldname": {
"value": "511"
}
}
}
}
wildcard通配符(不常用)
{
"query": {
"wildcard": {
"fieldname": {
"value": "*110*"
}
}
}
}
regexp正则搜索(不常用)
{
"query": {
"regexp": {
"fieldname": {
"value": "[0-9]11.+"
}
}
}
}
term精确查询
term是代表完全匹配,也就是精确查询,搜索前不会再对搜索词进行分词,所以我们的搜索词必须是文档分词集合中的一个。所以文档的分词要集合中要命中一个完整的查询字符串才能显示出来。
如果title为英文文档,那么先根据空格把title分词,在看所有的分词是否命中"request submissionContext",显然不会命中任何结果,因为分词不会有空格。
{
"query":{
"term":{
"title":"request submissionContext"
}
}
}
{
"terms":{
"message":"submissionContext",
"a1":"submissionContext"
}
}