query语法

一、query 允许我们使用Query DSL的方式查询。

查询常用的关键字如下:

1 query 

  • term:精准匹配document的某个字段,不会对被查询的值进行分词。
  • match:首先对被查询的值进行分词,然后用评分机制进行打分,并将所有查询的字段中包含该分词的都返回
  • bool:结合其它真值查询,通常和must\should\mustnot(与或非)一起组合出复杂的查询。
  • range:范围查询。查询时指定某个字段在某个特定的范围。
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "message": "'name' must not null"
          }
        },
        {
          "term": {
            "level.keyword": {
              "value": "INFO"
            }
          }
        },
        {
          "range": {
            "@timestamp": {
              "gte": "2019-09-05T09:56:58"
            }
          }
        }
      ],
      "must_not": [
        {
          "term": {
            "level.keyword": {
              "value": "DEBUG"
            }
          }
        }
      ]
    }
  },
  "from": 100,
  "size": 20, 
  "sort": [
    {
      "@timestamp": {
        "order": "asc"
      }
    }
  ]
}

2 sort  根据某个字段排序 

"sort": [
    {
      "@timestamp": {
        "order": "asc"
      }
    }
  ]

3 _source  指定查询结果中展示的字段。   "_source": ["a", "b"]

4 size  指定检索结果输出的条数,不设定时默认为10。   "size": 20

5 from  以一定的偏移量来检索我们的数据,缺省时默认为0(从检索的第一条数据开始)。"from": 10

猜你喜欢

转载自www.cnblogs.com/mydesky2012/p/11469767.html