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"
}
}
}
ES的基本操作
最新推荐文章于 2023-01-04 17:30:58 发布