使用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
}
}
}
}
}
}
- 布尔查询多条件匹配
- must (相对于and)
GET /test1/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "程序员"
}
},
{
"match": {
"age": "22"
}
}
]
}
}
}
- 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": {}
}
}
}