es基本语法

put /索引/类型

put   /索引/类型/1
{
json串
}
POST /索引/类型/1/_update
{
“doc”:{
列名:值//进准修改其中某个列
}
}

DELETE /索引

POST /_bulk  ---批量操作增删改
--必须写在同一行
{“create”:{“_index”:索引,“_type”:类型,“_id”:编号}}
{json串}
{“update”:{“index”:索引,“_type”:类型,“_id”:编号}}
“doc”:{json串}
{“delete”:{“index”:索引,“_type”:类型,“_id”:编号}}
GET  /索引/类型/_search   查询所有

GET  /索引/类型/_search
{“query”:{“match_all”:{}}}
GET /索引/类型/1?_source=字段列表
GET  /索引/类型/_search
{“query”:{
“match”:{json串}
}
}

修改单个数据content:

PUT abc/article/1
{
  "content":"content"        #修改
}
GET _analyze
{
  "analyzer": "whitespace",        #按空格分
  "text": ["我 是 huijia回家","要回家   啊 "]
}



#更新
POST abc/article/_bulk
{
  "updata":{
    "_index":"abc",
    "_type":"article",
    "_id":"1",
    "doc":{
      "id":"2",
      "title":"biaot标题2",
      "context":"context"
    }
  }
}

添加信息:
1

PUT _bulk
{"create":{"_index":"abc","_type":"article","_id":"1"}}         #不能空格回车分开
{"id":"1","name":"sam","age":"18"}

2

PUT /abc/article/1
{"id": 1, "studentNo": "TH-CHEM-2016-C001", "name":"Jonh Smith", "major":"Chemistry", "gpa": 4.8,"yearOfBorn": 2000, "classOf": 2016,  "interest":"soccer, basketball, badminton, chess"}
GET  def/stu/_search
#查询所有数据

添加多条信息语句

**#添加多条信息语句**
POST _bulk
{"create":{"_index":"def","_type":"stu","_id":"2"}}         #每条都要加  添加信息
{"id": 2, "studentNo": "TH-CHEM-2016-C001", "name":"Jonh Smith", "major":"Chemistry", "gpa": 4.8,"yearOfBorn": 2000, "classOf": 2016,  "interest":"soccer, basketball, badminton, chess"}
{"create":{"_index":"def","_type":"stu","_id":"3"}}
{"id": 3, "studentNo": "TH-PHY-2018-C001", "name": "Isaac Newton","major":"Physics", "gpa": 3.6, "yearOfBorn": 2001, "classOf": 2018,"interest": "novel, soccer, cooking"}
{"create":{"_index":"def","_type":"stu","_id":"4"}}
{"id": 4, "studentNo": "BU-POLI-2016-C001", "name": "John Kennedy","major":"Politics", "gpa": 4.2, "yearOfBorn": 2000, "classOf": 2016,"interest": "talking, dating, boxing, shooting, chess"}
{"create":{"_index":"def","_type":"stu","_id":"5"}}
{"id": 5, "studentNo": "BU-POLI-2015-C001", "name": "John Kerry","major":"Politics", "gpa": 4.1, "yearOfBorn": 1999, "classOf": 2015,"interest": "money, basketball"}
{"create":{"_index":"def","_type":"stu","_id":"6"}}
{"id": 6, "studentNo": "BU-ARTS-2016-C002", "name": "Da Vinci","major":"Arts", "gpa": 4.8, "yearOfBorn": 1995, "classOf":2016,"interest": "drawing, music, wine"}
PUT  demo.1234
{
  "settings": {
    "index":{
      "number_of_shards":3,       #number_of_replicas 是数据备份数,如果只有一台机器,设置为0
      "number_of_replicas":2       #是数据分片数,默认为5,有时候设置为3
    }
  }
}
DELETE demo.1234     #删除节点
GET _analyze
{
  "analyzer": "standard",
  "text": ["Tom lives in Guangzhou,I live in Guangzhou too.","He once lived in Shanghai."]
}

按照classOf 降序查询(desc)

GET def/stu/_search?sort=classOf:desc      

分页查询


GET def/stu/_search?scroll=3m
{
  "query": {
    "match_all": {}
  }
  ,"size": 3        #三条数据
  ,"from": 0        #从第0开始
}
GET _search/scroll
{
  "scroll_id":"DnF1ZXJ5VGhlbkZldGNoBQAAAAAAAABZFnpSdVVuQ0drVEstcENZcGtmYnNDMlEAAAAAAAAASRZxcUFOMWxxV1JrZTFtdGJBWXpzcExnAAAAAAAAAEsWWlZJbUFZZlRRWnVVQm5uVE5VMnFzZwAAAAAAAABYFnpSdVVuQ0drVEstcENZcGtmYnNDMlEAAAAAAAAAShZxcUFOMWxxV1JrZTFtdGJBWXpzcExn",
  "scroll":"3m"
}

按姓名查询

GET def/stu/_search
{
  "query": {
    "match": {
      "name":"Da Vinci"
    }
  }
}

查询所有

GET def/stu/_search
{
  "query": {
    "match_all": {}
  }
}

短句查询

GET def/stu/_search
{
  "query": {
    "match_phrase": {
      "interest": "music"
    }
  }
  }

模糊查询

GET def/stu/_search
{
  "query": {
    "multi_match": {
      "query": "Da Vinci like music",
      "fields": ["name", "interest"]
    }
  }
}
GET  def/stu/_search
{"query": {
  "term": {
      "name": "da"
    
  }
}
}

按照范围查询

#现在都是包含两边,不加 gt的 e 不包含 
GET def/stu/_search
{"query": {
  "range": {
    "gpa": {
      "gte": 4.1,
      "lte": 4.8
    }
  }
}
}

查询多条条件

GET /def/stu/_search
{"query": {
  "bool": {
    "must": [
      {"match_phrase": {
        "name": "Da"
      }
        
      }
      , {"match": {
          "yearOfBorn": "1995"
        }}
      
    ]
    ,
    "must_not": [
      {"match": {
        "id": "5"
      }}
    ]
    ,
    "should": [
      {"match_phrase_prefix": {
        "interest": "music"
      }}
    ]
    ,"minimum_should_match": 1    #  为至少满足should的 1 条
  }
}
}

待补。。。。

你可能感兴趣的:(大数据)