目录: 一、 针对这次装B 的解释
四、 查询
四、 查询
1. 查询的官网的文档
- took —— Elasticsearch执行这个搜索的耗时,以毫秒为单位- timed_out —— 指明这个搜索是否超时
- _shards —— 指出多少个分片被搜索了,同时也指出了成功/失败的被搜索的shards的数量
- hits —— 搜索结果
- hits.total —— 能够匹配我们查询标准的文档的总数目
- hits.hits —— 真正的搜索结果数据(默认只显示前10个文档)- _score和max_score —— 现在先忽略这些字段
1 "query":{ 2 "match":{ 3 "UserName":"BWH-PC" 4 } 5 }
1 { 2 "query": { 3 "match": { 4 "text": "quick fox" 5 } 6 } 7 }
相当于
1 { 2 "query": { 3 "bool": { 4 "should": [ 5 { 6 "term": { 7 "text": "quick" 8 } 9 }, 10 { 11 "term": { 12 "text": "fox" 13 } 14 } 15 ] 16 } 17 } 18 }
1 { 2 "query": { 3 "multi_match": { 4 "query": "bbc0641345dd8224ce81bbc79218a16f", 5 "operator": "or", 6 "fields": [ 7 "*.machine" 8 ] 9 } 10 } 11 }
1 { 2 "bool": { 3 "must": { 4 "match": { 5 "title": "how to make millions" 6 } 7 }, 8 "must_not": { 9 "match": { 10 "tag": "spam" 11 } 12 }, 13 "should": [ 14 { 15 "match": { 16 "tag": "starred" 17 } 18 }, 19 { 20 "range": { 21 "date": { 22 "gte": "2014-01-01" 23 } 24 } 25 } 26 ] 27 } 28 }
1 "term": { 2 "CapabilityDescriptions": "aa" 3 }
1 { 2 "query": { 3 "bool": { 4 "should": [ 5 { 6 "constant_score": { 7 "query": { 8 "match": { 9 "description": "wifi" 10 } 11 } 12 } 13 }, 14 { 15 "constant_score": { 16 "query": { 17 "match": { 18 "description": "garden" 19 } 20 } 21 } 22 }, 23 { 24 "constant_score": { 25 "boost": { 26 "query": { 27 "match": { 28 "description": "pool" 29 } 30 } 31 } 32 } 33 } 34 ] 35 } 36 } 37 }
missing相当于is null【没查到的是null】
1 { 2 "query": { 3 "filtered": { 4 "query": { 5 "match": { 6 "email": "business opportunity" 7 } 8 }, 9 "filter": { 10 "term": { 11 "folder": "inbox" 12 } 13 } 14 } 15 } 16 }
1 { 2 "query": { 3 "filtered": { 4 "filter": { 5 "bool": { 6 "must": { 7 "term": { 8 "folder": "inbox" 9 } 10 }, 11 "must_not": { 12 "query": { 13 "match": { 14 "email": "urgent business proposal" 15 } 16 } 17 } 18 } 19 } 20 } 21 } 22 }
1 "range": { 2 "price": { 3 "gt": 20, 4 "lt": 40 5 } 6 }
1 { 2 "query": { 3 "filtered": { 4 "filter": { 5 "range": { 6 "price": { 7 "gte": 20, 8 "lt": 40 9 } 10 } 11 } 12 } 13 } 14 }
1 { 2 "range": { 3 "timestamp": { 4 "gt": "2014-01-0100: 00: 00", 5 "lt": "2014-01-0700: 00: 00" 6 } 7 } 8 }
1 { 2 "range": { 3 "timestamp": { 4 "gt": "now-1h" 5 } 6 } 7 }
后置过滤--post_filter元素是一个顶层元素,只会对搜索结果进行过滤。警告:性能考量只有当你需要对搜索结果和聚合使用不同的过滤方式时才考虑使用post_filter。有时一些用户会直接在常规搜索中使用post_filter。不要这样做!post_filter会在查询之后才会被执行,因此会失去过滤在性能上帮助(比如缓存)。post_filter应该只和聚合一起使用,并且仅当你使用了不同的过滤条件时。
1 { 2 "query": { 3 "query_string": { 4 "query": "*" 5 } 6 }, 7 "post_filter": { 8 "bool": { 9 "should": { 10 "query": { 11 "bool": { 12 "should": [ 13 { 14 "match": { 15 "machine": "bbc0641345dd8224ce81bbc79218a16f" 16 } 17 }, 18 { 19 "match": { 20 "machine": "bbc0641345dd8224ce81bbc79218a16f" 21 } 22 } 23 ] 24 } 25 } 26 } 27 } 28 } 29 }
当然,在里面的每一个should中,可以去做很多变形,但是should多个子类时,必须用[]
1 { 2 "query": { 3 "query_string": { 4 "query": "*" 5 } 6 }, 7 "post_filter": { 8 "bool": { 9 "should": [ 10 { 11 "query": { 12 "bool": { 13 "must": [ 14 { 15 "multi_match": { 16 "query": "bbc0641345dd8224ce81bbc79218a16f", 17 "operator": "or", 18 "fields": [ 19 "*.machine", 20 "" 21 ] 22 } 23 }, 24 { 25 "multi_match": { 26 "query": "10.10.185.99", 27 "operator": "or", 28 "fields": [ 29 "*.IPAddress", 30 "" 31 ] 32 } 33 } 34 ] 35 } 36 } 37 }, 38 { 39 "query": { 40 "bool": { 41 "must": [ 42 { 43 "match": { 44 "machine": "bbc0641345dd8224ce81bbc79218a16f" 45 } 46 }, 47 { 48 "match": { 49 "IPAddress": "10.10.11.11" 50 } 51 } 52 ] 53 } 54 } 55 } 56 ] 57 } 58 } 59 }
1 { 2 "query": { 3 "filtered": { 4 "query": { 5 "query_string": { 6 "query": "*" 7 } 8 }, 9 "filter": { 10 "bool": { 11 "should": { 12 "query": { 13 "bool": { 14 "should": [ 15 { 16 "multi_match": { 17 "query": "a2", 18 "operator": "or", 19 "fields": [ 20 "*.last" 21 ] 22 } 23 }, 24 { 25 "match": { 26 "last": "a2" 27 } 28 } 29 ] 30 } 31 } 32 } 33 } 34 } 35 } 36 } 37 }
所有评论(0)