十一、ElasticSearch6.4.0 API

es/API 版本6.4.0,es7的API往往不用加_doc

## 创建非结构化索引,默认5个分片,1个副本。由于现在单节点演示,index状态是yellow
PUT /employee/_doc/1
{
 "name":"wcq",
 "age":25
}

## 获取索引的mapping、settings
GET /employee/_mapping
GET /employee/_settings

## 也可以在创建索引时指定
PUT /employee
{
  "settings": {
    "number_of_shards": 5,
    "number_of_replicas": 1
  }
}

## 修改副本个数信息,发现index状态变green
PUT /employee/_settings
{
  "number_of_replicas": 0
}

## 全量替换文档
PUT /employee/_doc/1
{
 "name":"hmq",
 "age":27
}

## 部分更新文档
POST /employee/_doc/1/_update
{
   "doc":{
     "age":17 
   }
}

## 获取文档
GET /employee/_doc/1

## 强制创建文档,如果已经存在则操作失败
PUT /employee/_doc/1/_create
{
 "name":"宋江",
 "age":42
}

## 创建结构化索引
PUT /employee2
{
    "settings": {
        "number_of_replicas": 0,
        "number_of_shards": 2
    },
    "mappings": {
        "_doc": {
            "properties": {
                "name": {
                    "type": "text"
                },
                "age": {
                    "type": "integer"
                }
            }
        }
    }
}

## 简单搜索, order by socre desc,id desc 
GET /employee/_search
{
  "query": {
    "match_all": {}
  }, 
  "from": 0,
  "size": 20
}

## 带关键字搜索,指定排序字段后_score返回的就是null,另有sort字段放自定义排序分,带简单聚合
GET /employee/_search
{
  "query": {
    "match": {
      "name": "李"
    }
  },
  "sort": [
    {
      "age": {
        "order": "desc"
      }
    }
  ],
  "aggs": {
    "agg_by_age": {
      "terms": {
        "field": "age"
      }
    }
  }
}

## filter过滤(match or term),返回的_score是0,不会计算分数
GET /employee/_search
{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "name": "李"
        }
      }
    }
  }
}




PUT /goodsay/_doc/1
{
  "say":"good minds think all like"
}

## 搜索不到,默认使用standand分词器,只会按空格标点符号分割。没有词根转换、单复数转换等
GET /goodsay/_search
{
  "query": {
    "match": {
      "say": "mind"
    }
  }
}

DELETE /goodsay

## 指定分词器
PUT /goodsay
{
    "settings": {
        "number_of_replicas": 0,
        "number_of_shards": 2
    },
    "mappings": {
        "_doc": {
            "properties": {
                "say": {
                    "type": "text",
                    "analyzer":"english"
                }
            }
        }
    }
}

## 分词分析
GET /goodsay/_analyze
{
  "field": "say",
  "text": "good minds think all like"
}

常用数据类型

text、keyword、date、long、integer、short、double、boolean、Array数组、json嵌套、IP类型、Geo_point

你可能感兴趣的:(十一、ElasticSearch6.4.0 API)