es索引数据过滤查询

2024-01-07 23:52:38

1.我们往kibana插入数据,来进行查询

POST /t1/_doc/
{
  "name":"cat",
  "age":"18",
  "address":"BJ",
  "job":"dev"
}
POST /t1/_doc/
{
  "name":"dog",
  "age":"19",
  "address":"SD",
  "job":"ops"
}
POST /t1/_doc/
{
  "name":"alice",
  "age":"20",
  "address":"BJ",
  "job":"dev"
}
POST /t1/_doc/
{
  "name":"tigger",
  "age":"20",
  "address":"AH",
  "job":"ops"
}
POST /t1/_doc/
{
  "name":"fix",
  "age":"21",
  "address":"HN",
  "job":"dev"
}
POST /t1/_doc/
{
  "name":"jack",
  "age":"18",
  "address":"BJ",
  "job":"dev"
}
POST /t1/_doc/
{
  "name":"Tom",
  "age":"21",
  "address":"HN",
  "job":"ops"
}

2.查询

#term查询,是根据具体的字段进行查询
#查询所有
GET t1/_search

#查询name为cat的
GET t1/_search
{
  "query": {
    "term": {
      "name.keyword": {
        "value": "cat"
      }
    }
  }
  
}
#查询地区为北京的
GET t1/_search
{
  "query": {
    "term": {
      "address.keyword": {
        "value": "BJ"
      }
    }
  }
  
}


#bool查询 逻辑判断是否
bool组合语法
must:必须符合,包含    与AND等价
should:满足任意的条件,  与or等价
filter:必须满足,是否命中,不计算分值,等同must
must_not:  必须不符合不包含   与not等价

#查询工作为ops的,且年龄为19到20岁的
GET t1/_search
{
  "query": {
    "bool": {
      "must": [
        {"match": {    #我要查询job必须是包含ops的
          "job": "ops"
        }}
      ],
      "filter": [
        {
          "range": {
            "age.keyword": {
              "gte": 19,
              "lte": 20
            }
          }
        }
      ]
    }
  }
}

结果

在这里插入图片描述

3通过elassearch插件查询,找出北京,年纪为20岁的

在这里插入图片描述

文章来源:https://blog.csdn.net/2201_76119904/article/details/135373797
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。