es索引数据过滤查询

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
            }
          }
        }
      ]
    }
  }
}

结果

es索引数据过滤查询_第1张图片

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

es索引数据过滤查询_第2张图片

你可能感兴趣的:(elasticsearch,数据库,大数据,运维,服务器,linux,搜索引擎)