- ### 查询所有
- GET _search
- {
- "query": {
- "match_all": {}
- }
- }
-
- ### 查询单个索引 的 固定属性
-
- --- 精确匹配
-
- GET _search
- {
- "query": {
- "term": { "name" : "you" }
- }
- }
-
- ### 模糊匹配
-
- GET _search
- {
- "query": {
- "match": { "name" : "you" }
- }
- }
- ### 范围查找
-
- GET _search
- {
- "query": {
- "range": {
- "age":{ "gte" : 15 , "lte" : 25 }
- }
- }
- }
- ### 功能性查询
-
- --- 过滤
-
- GET my_index/_search
- {
- "query": {
- "bool": {
- "filter": {
- "term":{"age":1095}
- }
- }
- }
- }
-
- --- 或 or
-
- GET my - test / _search {
- "query": {
- "bool": {
- "should": [{
- "term": {
- "name": "you"
- }
- }, {
- "match": {
- "age": 20
- }
- }]
- }
- }
- }
-
- --- 与 AND
-
- GET my-test/_search
- {
- "query": {
- "bool": {
- "must" : [{
- "match" : {
- "name" : "you"
- }
- },{
- "range":{
- "age":{
- "from" : 10 , "to" : 20
- }
- }
- }]
- }
- }
- }
-
- ---必须 =
-
- GET my_index/_search
- {
- "query": {
- "bool": {
- "must" : {
- "range" : {
- "age" : { "from" : 10, "to" : 20 }
- }
- }
- }
- }
- }
-
- --- 必须不 not
-
- GET my_index/_search
- {
- "query": {
- "bool": {
- "must_not" : {
- "term" : {
- "name" : "you"
- }
- }
- }
- }
- }
-
- ## 复合查找
-
- GET my_index/_search
- {
- "query": {
- "bool": {
- "should": [{
- "match": {
- "age": 40
- }
- },
- {
- "match": {
- "age": 20
- }
- }],
- "filter": {
- "match":{
- "name":"you"
- }
- }
- }
- }
- }
- ### 参考文档
- https://zhuanlan.zhihu.com/p/370392324
- ##
- HEAD myindex/_doc/1
- ###
- GET mes-data-api-daemon-2022.11.16/_search?size=1
- {
-
- }
常用于模糊搜索
- ## 查询指定索引的匹配查询
- GET mes-data-api-daemon-2022.11.16/_search
- {
- "query": {
- "match": {
- "message": "请检查执行机器列表信息"
- }
- }
- }
常用于精确匹配
- GET test_record/_search
- {
- "query": {
- "term": {
- "sn" : "H101ZAB1ZE7G0002"
- }
- }
- }
多个条件同时满足才返回
- ###
- GET mes-data-api-daemon-2022.11.16/_search
- {
- "query": {
- "bool": {
- "should": [
- {
- "match": {
- "_id" : "o_kGfIQB8nBHSUlxPl-L"
- }},
- {
- "match": {
- "host.name": "xx-xx-mes-app-prd-01"
- }
- }
- ]
- }
-
- }
- }