使用kibana对elasticsearch进行基本操作

使用kibana对elasticsearch进行基本操作

term会直接精确匹配,match会使用分词器解析,Keyword类型不会被解析器解析。

1. 基础测试

创建索引

PUT /test1
{
  "mappings": {
    "properties": {
      "name":{
        "type": "text"
      },
      "age":{
        "type": "integer"
      },
      "birthday":{
        "type": "date"
      }
    }
  }
}

查看索引

GET /test1

向索引中添加数据

PUT /test1/_doc/1
{
  "name":"程序员",
  "age":"15",
  "birthday":"1999-09-23"
}

修改数据

POST /test1/_doc/1/_update
{
    "doc":{
      "name":"项目经理"
    }
}

删除索引

DELETE test1

2. 搜索

  • 模糊匹配
GET /test1/_search
{
  "query":{
    "match":{
      "name":"项目经理"
    }
  }
}
  • 匹配字段过滤
GET /test1/_search
{
  "query":{
    "match":{
      "name":"项目经理"
    }
  },
  "_source": ["name","age"]
}
  • 精确匹配
GET test1/_search
{
  "query": {
    "term": {
        "name": "程"
    }
  }
}
  • 查询过滤
GET /test1/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "程序员"
          }
        }
      ],
      "filter": {
        "range": {
          "age": {
            "gte": 10,
            "lte": 20
          }
        }
      }
    }
  }
}
  • 布尔查询多条件匹配
  1. must (相对于and)
GET /test1/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "程序员"
          }
        },
        {
          "match": {
            "age": "22"
          }
        }
      ]
    }
  }
}
  1. should (相对于or)
GET /test1/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "name": "程序员"
          }
        },
        {
          "match": {
            "age": "19"
          }
        }
      ]
    }
  }
}
  • 查询并且排序
GET /test1/_search
{
  "query": {
    "match": {
      "name": "程序员"
    }
  },
  "sort": [
    {
      "age": {
        "order": "desc"
      }
    }
  ]
}
  • 分页查询
GET /test1/_search
{
  "query": {
    "match": {
      "name": "程序员"
    }
  },
  "from": 0
  , "size": 1
}
  • 高亮查询并且自定义高亮属性
GET test1/_search
{
  "query": {
    "term": {
      "name": {
        "value": "程"
      }
    }
  }
  , "highlight": {
    "pre_tags": "<p style='color:red'>",
    "post_tags": "</p>", 
    "fields": {
      "name": {}
    }
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值