es常用查询学习记录

Posted yaohaitao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了es常用查询学习记录相关的知识,希望对你有一定的参考价值。

DELETE /test

PUT /test
{
"settings": {
"number_of_shards": 10,
"number_of_replicas": 1
}
}

DELETE /employee
##非结构化新建索引

PUT /employee
{
"settings": {
"number_of_replicas": 1
, "number_of_shards": 1
}
}


PUT /employee/_doc/1
{
"name":"凯杰2",
"age":30
}


PUT /employee/_doc/1
{
"name":"凯杰3"
}

##获取索引记录
GET /employee/_doc/1

#指定字段修改
POST /employee/_update/1
{
"doc": {
"name":"凯杰4"
}
}

#强制指定创建,若已经存在则失败
POST /employee/_create/6
{
"name":"兄长2",
"age":"31"
}

#删除某个文档
DELETE /employee/_doc/2

#查询全部文档
GET /employee/_search

#使用结构化的方式创建索引
PUT /employee
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"name":{"type":"text"},
"age":{"type": "integer"}
}
}
}

#不带条件查询所有记录的方法
GET /employee/_search
{
"query": {
"match_all": {}
}
}

#分页查询
GET /employee/_search
{
"query": {
"match_all": {}
}
, "from": 0,
"size": 2
}

#带关键字条件查询
GET /employee/_search
{
"query":{
"match": {
"name": "兄"
}
}
}

#带排序
GET /employee/_search
{
"query":{
"match": {
"name": "兄"
}
}, "sort":[
{"age":{"order":"asc"}}
]
}

#带filter term完全匹配 match 分词匹配
GET /employee/_search
{
"query": {
"bool": {
"filter": [
{"term":{"name":"兄111"}}
]
}
}
}

#带聚合
GET /employee/_search
{
"query": {
"match": {
"name": "兄"
}
},"sort": [
{
"age": {
"order": "desc"
}
}
],
"aggs": {
"group_by_age": {
"terms": {
"field": "age"
}
}
}
}

#新建一个索引
PUT /movie/_doc/1
{
"name":"Eating an apple a day & keeps the doctor away"
}

GET /movie/_search
{
"query": {
"match": {
"name": "appl"
}
}
}

#使用analyze api查看分词状态 过滤两次(1.量词,特殊字符 2.词干 英文会大写变小写方便查询)
GET /movie/_analyze
{
"field": "name",
"text":"Eating an apple a day & keeps the doctor away"
}

DELETE /movie

#使用结构化方式创建索引

PUT /movie
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"name":{"type": "text","analyzer": "english"}
}
}
}

GET /movie/_search

#Text 被分析索引的字符串类型
#keyword不能被分析只能被精确匹配的字符串类型
#Date日期类型,可以配合format一起使用
#数字类型 long interger short double
#boolean true false
#Array one two
#Object json嵌套
#IP 类型
#Geo_point地址位置

 

以上是关于es常用查询学习记录的主要内容,如果未能解决你的问题,请参考以下文章

Typescript学习记录

ES6学习记录

ES盲点记录

ES盲点记录

ES盲点记录

es6学习记录