ES的基本操作

PUT /product
 POST /product/_mapping
 {
   "properties":
  {
     "id":
     {
     "type":"integer",
      "store":true,
      "index":true
     },
   "productName":
   {
     "type":"text",
     "store":true,
     "index":true
     
   },
   "produceDesc":
   {
     "type":"text",
     "store":true,
     "index":true
   } 
  }
 }
 
 
 
PUT /product2
{
  "mappings": {
    "properties": {
      "id": {
        "type": "integer",
        "store": true,
        "index": true
      },
      "productName": {
        "type": "text",
        "store": true,
        "index": true
      },
      "produceDesc": {
        "type": "text",
        "store": true,
        "index": true
        
      }
    }
  }
}


DELETE /product1


POST /product/_doc/1
{
  "id":10001,
  "productName":"ihone12",
  "productDesc":"ihone12是苹果的最新手机!"
}

POST /product/_doc/2
{
  "id":10001,
  "productName":"ihone13",
  "productDesc":"ihone13是苹果的最新手机!"
}


POST /product/_doc/
{
  "id":10001,
  "productName":"mate40",
  "productDesc":"Mate 40是苹果的最新手机!"
}



GET /product/_doc/bKnVZH0BCXZECWvnsmPQ


GET //product/_mget
{
  "docs": [
    {
      "_id": 1
    },
    {
      "_id": 2
    }
  ]
}



GET /product1/_search
{
"query": {
"match_all": {}
}
}

POST /product/_doc/1/_update
{
  "doc": {
    "productName": "苹果派"
  }
}



POST /product1/_doc/1
{
  "id":1,
  "productName":"elallalla",
  "productDesc":"I love you "
}

GET /product1/_search
{
  "query": {
    "term": {
      "produceDesc": "love"
    }
  }
}



GET /product1/_search
{
  "stored_fields": [
    "produceName"
  ]
}








PUT /student
{
  "mappings": {
    "properties": {
      "id": {
        "type": "integer",
        "store": true,
        "index": true
      
      },
      "studentName": {
        "type": "text",
        "store": true,
        "index": true
        , "analyzer": "ik_max_word"
      },
      "info": {
        "type": "text",
        "store": true,
        "index": true
        , "analyzer": "pinyin"
        
      }
    }
  }
}



POST /student/_doc/5
{
  "id":10001,
  "sudentName":"喜洋洋!",
  "info":"喜洋洋是羊村最聪明的羊!"
}


POST /student/_doc/2
{
  "id":10002,
  "sudentName":"喜洋洋!",
  "info":"tom is a good boy!"
}
POST /student/_doc/3
{
  "id":10003,
  "sudentName":"lanyanyang!",
  "info":"tom is a good boy!"
}


GET /student/_search
{
  "query": {
    "term": {
      "info":"聪明"
    }
  }
}

GET /_analyze
{
  "text": "tom is a good boy",
  "analyzer": "standard"
}


GET /_analyze
{
  "text": "喜洋洋是羊村最聪明的羊",
  "analyzer": "ik_smart"
}



GET /_analyze
{
  "text": "喜洋洋是羊村最聪明的羊",
  "analyzer": "ik_max_word"
}



GET /student/_search
{
  "query": {
    "term": {
      "info":"聪明"
    }
  }
}


GET /_analyze
{
  "text": "喜洋洋是羊村最聪明的羊",
  "analyzer": "pinyin"
}

DELETE /student

PUT /student
{
  "settings": {
    "analysis": {
      "analyzer": {
        "ik_pinyin": {
          "tokenizer": "ik_max_word",
          "filter": "pinyin_filter"
        }
      },
      "filter": {
        "pinyin_filter": {
          "type": "pinyin",
          "keep_separate_first_letter": false,
          "keep_full_pinyin": true,
          "keep_original": true,
          "remove_duplicated_term": true
        }
      }
    }
  }
}



GET /student/_analyze
{
  "text": "我么是是啊",
  "analyzer": "ik_pinyin"
}

GET /student/_search
{
  "query": {
    "match_all": {}
  }
}

GET /student/_search
{
  "query": {
    "match_all": {}
  }
}


GET /student/_search
{
  "query": {
    "match_phrase": {
      "info": "羊"
    }
  }
}

-- 根据id 查询的数量
GET /student/_search
{
  "query": {
    "range": {
      "id": {
        "gte": 10001,
        "lte": 10002
      }
    }
  }
}
-- 根据条件查询数据
GET /student/_search
{
  "query": {
    "term": {
      "info": "羊"
    }
  }
}


-- 添加数据
POST /student/_doc/3
{
  "id":10003,
  "sudentName":"lanyanyang!",
  "info":"tom is a good boy!"
}




-- 模糊查询 ,自动纠错
GET /student/_search
{
  "query": {
    "match": {
      "info": {
        "query": "go",
        "fuzziness": 2  -- 这个数<=2
      }
    }
  }
}



-- 排序
GET /student/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "info": "是"
          }
        },
        {
          "match": {
            "info": "聪明"
          }
        }
      ]
    }
   
  },
  "sort": [
    {
      "id": {
        "order": "desc"
      }
    }
  ]
}


-- 高亮查询数据
GET /student/_search
{
  "query": {
    "match": {
      "info": "是"
    }
  },
  "sort": [
    {
      "id": {
        "order": "asc"
      }
    }
  ],
  "from": 0,
  "size": 10,
  "highlight": {
    "fields": {
      "info": {
        "fragment_size": 20,
        "number_of_fragments": 5
      }
    },
    "pre_tags": ["<em>"],
    "post_tags": ["</em>"]
  }
}

-- 使用sql操作es
GET /_sql?format=txt
{
  "query": "select * from student ",
  "filter": {
    "match": {
      "info": "good"
    }
  }
}













  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值