GET /_cat/health?v
GET /_cat/indices?v
PUT /product_index
DELETE /product_index
DELETE /product_index,order_index
DELETE /product_*
DELETE /_all
GET /product_index/_settings
GET /product_index,order_index/_settings
GET /_all/_settings
PUT /order_index
{
"settings": {
"index": {
"number_of_shards": 5,
"number_of_replicas": 1
}
}
}
PUT /order_index/_settings
{
"number_of_replicas": 2
}
PUT /product_index
{
"settings": {
"refresh_interval": "5s",
"number_of_shards": 5,
"number_of_replicas": 1
},
"mappings": {
"product": {
"properties": {
"id": {
"type": "text",
"index": "not_analyzed"
},
"product_name": {
"type": "text",
"store": "no",
"term_vector": "with_positions_offsets",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"boost": 5
},
"product_desc": {
"type": "text",
"index": "not_analyzed"
},
"price": {
"type": "double",
"index": "not_analyzed"
},
"created_date_time": {
"type": "date",
"index": "not_analyzed",
"format": "basic_date_time"
},
"last_modified_date_time": {
"type": "date",
"index": "not_analyzed",
"format": "basic_date_time"
},
"version": {
"type": "long",
"index": "no"
}
}
}
}
}
{
"email": "[email protected]",
"login_name": "youmeek",
"card_info": {
"card_name": "zhangsan",
"card_num": "350111199002205317"
},
"create_date": "2017-05-30 12:04:54"
}
PUT /product_index/product/1
{
"product_name" : "PHILIPS toothbrush HX6730/02",
"product_desc" : "【3?9 元,前 1000 名赠刷头,6 月 1 日 0 点火爆开抢,618 开门红巅峰 48 小时,抢先加入购物车】飞利浦畅销款,万千好评!深入净齿,智能美白!",
"price" : 399.00
}
PUT /product_index/product/2
{
"product_name" : "Braun toothbrush 2000 3D",
"product_desc" : "6 月 1 日 16 点秒杀,仅 329 元!限量 1000 支,抢完即止!带压力感应提醒,保护牙龈,高效清洁",
"price" : 499.00
}
PUT /product_index/product/3
{
"product_name" : "iphone7 shell",
"product_desc" : "一说到星空,就有太多美好的记忆,美丽的浩瀚宇宙,有太多说不清的神秘之处,星空太美丽,太绚烂!",
"price" : 36.00
}
PUT /product_index/product/4
{
"product_name" : "iphone7 shell4",
"product_desc" : "一说到星空4,就有太多美好的记忆,美丽的浩瀚宇宙,有太多说不清的神秘之处,星空太美丽,太绚烂!",
"price" : 36.00
}
PUT /product_index/product/5
{
"product_name" : "iphone7 shell5",
"product_desc" : "一说到星空5,就有太多美好的记忆,美丽的浩瀚宇宙,有太多说不清的神秘之处,星空太美丽,太绚烂!",
"price" : 36.00
}
## POST 方式新增数据,不指向 ID 会自动生成一个 20 位的字符串 ID。
POST /product_index/product
{
"product_name" : "iphone6 shell",
"product_desc" : "真正 360° 全包边 防指纹防摔",
"price" : 28.00
}
GET /product_index/product/3
GET /product_index/product/3?_source=product_name,product_desc
GET /product_index/product/_search
GET /product_index/product/_search?timeout=5s
,官网资料GET /product_index,order_index/_search
GET /product_index,order_index/product,order/_search
GET /_all/product,order/_search
GET /product_*/_search
GET /product_index/product/_search?q=product_name:toothbrush&sort=price:desc
GET /product_index/product/_search?q=-product_name:toothbrush&sort=price:desc
GET /product_index/product/_search
GET /product_index/product/_search?from=0&size=2
GET /product_index/product/_search?from=2&size=2
GET /product_index/product/_search?from=4&size=2
GET /product_index/product/_search?scroll=1m
{
"query": {
"match_all": {}
},
"sort": [
"_doc"
],
"size": 2
}
GET /_search/scroll
{
"scroll": "1m",
"scroll_id" : "DnF1ZXJ5VGhlbkZldGNoBQAAAAAAABtNFlMxdDcyNlVaVHBtMDhkWDVIakZIVHcAAAAAAAAbUxYtQUdCeVVCY1RBSzI3eDFjVVlaZXpnAAAAAAAAG08WUzF0NzI2VVpUcG0wOGRYNUhqRkhUdwAAAAAAABtUFi1BR0J5VUJjVEFLMjd4MWNVWVplemcAAAAAAAAbThZTMXQ3MjZVWlRwbTA4ZFg1SGpGSFR3"
}
PUT /product_index/product/3
{
"product_name" : "星空太空 iphone7 plus 蓝紫色 6s 繁星 7plus 宇宙 se 原创保护苹果 5 包手机壳",
"product_desc" : "一说到星空,就有太多美好的记忆,美丽的浩瀚宇宙,有太多说不清的神秘之处,星空太美丽,太绚烂!",
"price" : 36.00
}
POST /product_index/product/3/_update
{
"doc": {
"product_name": "星空太空 iphone7 蓝紫色 6s 繁星 iphone7 plus 宇宙 se 原创保护苹果 5 包手机壳"
}
}
DELETE /product_index/product/3
,本质:标记为 deleted,等数据越来越大的情况 Elasticsearch 才去物理删除。GET /product_index/product/_search
,返回结果:{
"took": 3, ## 表示查询花费的时间(单位毫秒)
"timed_out": false, ## 是否超时
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3, ## 查询结果的数量
"max_score": 1, ## 最大相关数分数是 1,每一条查询出来的结果数据,跟 search 条件越相关的,排名越靠前,分数也就越大。
"hits": [ ## 查询结果的详细数据集合
{
"_index": "product_index",
"_type": "product",
"_id": "2",
"_score": 1,
"_source": {
"product_name": "Braun toothbrush 2000 3D",
"product_desc": "6 月 1 日 16 点秒杀,仅 329 元!限量 1000 支,抢完即止!带压力感应提醒,保护牙龈,高效清洁",
"price": 499
}
},
{
"_index": "product_index",
"_type": "product",
"_id": "1",
"_score": 1,
"_source": {
"product_name": "PHILIPS toothbrush HX6730/02",
"product_desc": "【3?9 元,前 1000 名赠刷头,6 月 1 日 0 点火爆开抢,618 开门红巅峰 48 小时,抢先加入购物车】飞利浦畅销款,万千好评!深入净齿,智能美白!",
"price": 399
}
},
{
"_index": "product_index",
"_type": "product",
"_id": "3",
"_score": 1,
"_source": {
"product_name": "iphone7 shell",
"product_desc": "一说到星空,就有太多美好的记忆,美丽的浩瀚宇宙,有太多说不清的神秘之处,星空太美丽,太绚烂!",
"price": 36
}
}
]
}
}
GET /product_index/product/_validate/query?explain
{
"query": {
"match": {
"product_name": "toothbrush"
}
}
}
GET /product_index/product/_search
{
"query": {
"match_all": {}
}
}
GET /product_index/product/_search
{
"query": {
"match": {
"product_name": "toothbrush"
}
},
"sort": [
{
"price": "desc"
}
]
}
GET /product_index/product/_search
{
"query": {
"match_all": {}
},
"from": 0, ## 从第几个商品开始查,最开始是 0
"size": 1 ## 要查几个结果
}
GET /product_index/product/_search
{
"query": {
"match_all": {}
},
"_source": [
"product_name",
"price"
]
}
符号标识 | 代表含义 |
---|---|
gte | 大于或等于 |
gt | 大于 |
lte | 小于或等于 |
lt | 小于 |
GET /product_index/product/_search
{
"query": {
"bool": {
"must": {
"match": {
"product_name": "toothbrush"
}
},
"filter": {
"range": {
"price": {
"gt": 400,
"lt": 700
}
}
}
}
}
}
GET /product_index/product/_search
{
"query": {
"match": {
"product_name": "PHILIPS toothbrush"
}
}
}
GET /product_index/product/_search
{
"query": {
"match_phrase": {
"product_name": "PHILIPS toothbrush"
}
}
}
"PHILIPS toothbrush HX6730/02"
GET /product_index/product/_search
{
"query": {
"match": {
"product_name": "PHILIPS toothbrush"
}
},
"highlight": {
"fields": {
"product_name": {}
}
}
}
GET /product_index/product/_search
{
"query": {
"range": {
"price": {
"gte": 30.00
}
}
}
}
GET /product_index/product/_search
{
"query": {
"match": {
"product_name": "PHILIPS toothbrush"
}
}
}
GET /product_index/product/_search
{
"query": {
"match": {
"product_name": {
"query": "PHILIPS toothbrush",
"operator": "and"
}
}
}
}
GET /product_index/product/_search
{
"query": {
"match": {
"product_name": {
"query": "java 程序员 书 推荐",
"minimum_should_match": "50%"
}
}
}
}
GET /product_index/product/_search
{
"query": {
"multi_match": {
"query": "toothbrush",
"fields": [
"product_name",
"product_desc"
]
}
}
}
GET /product_index/product/_search
{
"query": {
"multi_match": {
"query": "PHILIPS toothbrush",
"type": "cross_fields",
"operator": "and",
"fields": [
"product_name",
"product_desc"
]
}
}
}
GET /product_index/product/_search
{
"query": {
"match_phrase": {
"product_name": "PHILIPS toothbrush"
}
}
}
GET /product_index/product/_search
{
"query": {
"match_phrase": {
"product_name" : {
"query" : "PHILIPS HX6730",
"slop" : 1
}
}
}
}
GET /product_index/product/_search
{
"query": {
"bool": {
"must": {
"match": {
"product_name": {
"query": "PHILIPS HX6730"
}
}
},
"should": {
"match_phrase": {
"product_name": {
"query": "PHILIPS HX6730",
"slop": 10
}
}
}
}
}
}
GET /product_index/product/_search
{
"query": {
"match": {
"product_name": "PHILIPS HX6730"
}
},
"rescore": {
"window_size": 10,
"query": {
"rescore_query": {
"match_phrase": {
"product_name": {
"query": "PHILIPS HX6730",
"slop": 10
}
}
}
}
}
}
GET /product_index/product/_search
{
"query": {
"match_phrase_prefix": {
"product_name": "PHILIPS HX",
"slop": 5,
"max_expansions": 20
}
}
}
GET /product_index/product/_search
{
"query": {
"term": {
"product_name": "PHILIPS toothbrush"
}
}
}
GET /product_index/product/_search
{
"query": {
"constant_score": {
"filter":{
"term": {
"product_name": "PHILIPS toothbrush"
}
}
}
}
}
GET /product_index/product/_search
{
"query": {
"constant_score": {
"filter": {
"terms": {
"product_name": [
"toothbrush",
"shell"
]
}
}
}
}
}
GET /product_index/_search
{
"query": {
"bool": {
"must": [
{
"terms": {
"product_name": [
"PHILIPS",
"toothbrush"
]
}
},
{
"range": {
"price": {
"gt": 12.00
}
}
}
]
}
}
}
GET /product_index/product/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"price": {
"gte": 30.00
}
}
}
}
}
}
GET /product_index/product/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"product_name": "PHILIPS toothbrush"
}
}
],
"should": [
{
"match": {
"product_desc": "刷头"
}
}
],
"must_not": [
{
"match": {
"product_name": "HX6730"
}
}
],
"filter": {
"range": {
"price": {
"gte": 33.00
}
}
}
}
}
}
GET /product_index/product/_search
{
"query": {
"bool": {
"should": [
{
"term": {
"product_name": "飞利浦"
}
},
{
"bool": {
"must": [
{
"term": {
"product_desc": "刷头"
},
"term": {
"price": 30
}
}
]
}
}
]
}
}
}
GET /product_index/product/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"product_name": "java"
}
},
{
"match": {
"product_name": "程序员"
}
},
{
"match": {
"product_name": "书"
}
},
{
"match": {
"product_name": "推荐"
}
}
],
"minimum_should_match": 3
}
}
}
GET /product_index/product/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"product_name": "PHILIPS toothbrush"
}
}
],
"should": [
{
"match": {
"product_desc": "刷头"
}
}
],
"filter": {
"bool": {
"must": [
{
"range": {
"price": {
"gte": 33.00
}
}
},
{
"range": {
"price": {
"lte": 555.55
}
}
}
],
"must_not": [
{
"term": {
"product_name": "HX6730"
}
}
]
}
}
}
},
"sort": [
{
"price": {
"order": "desc"
}
}
]
}
GET /product_index/product/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"product_name": "toothbrush"
}
}
],
"should": [
{
"match": {
"product_name": {
"query": "PHILIPS",
"boost": 4
}
}
},
{
"match": {
"product_name": {
"query": "Braun",
"boost": 3
}
}
}
]
}
}
}
GET /product_index/product/_search
{
"query": {
"dis_max": {
"queries": [
{
"match": {
"product_name": "PHILIPS toothbrush"
}
},
{
"match": {
"product_desc": "iphone shell"
}
}
],
"tie_breaker": 0.2
}
}
}
GET /product_index/product/_search
{
"query": {
"dis_max": {
"queries": [
{
"match": {
"product_name": {
"query": "PHILIPS toothbrush",
"minimum_should_match": "50%",
"boost": 3
}
}
},
{
"match": {
"product_desc": {
"query": "iphone shell",
"minimum_should_match": "50%",
"boost": 2
}
}
}
],
"tie_breaker": 0.3
}
}
}
GET /product_index/product/_search
{
"query": {
"prefix": {
"product_name": {
"value": "iphone"
}
}
}
}
GET /product_index/product/_search
{
"query": {
"wildcard": {
"product_name": {
"value": "ipho*"
}
}
}
}
GET /product_index/product/_search
{
"query": {
"regexp": {
"product_name": "iphone[0-9].+"
}
}
}
GET /product_index/product/_search
{
"query": {
"match": {
"product_name": {
"query": "PHILIPS tothbrush",
"fuzziness": "AUTO",
"operator": "and"
}
}
}
}
DELETE /product_index?pretty
PUT /product_index/product/1
{
"product_name": "PHILIPS toothbrush HX6730/02",
"product_desc": "【3?9 元,前 1000 名赠刷头,6 月 1 日 0 点火爆开抢,618 开门红巅峰 48 小时,抢先加入购物车】飞利浦畅销款,万千好评!深入净齿,智能美白!",
"price": 399.00,
"tags": [
"toothbrush",
"PHILIPS"
]
}
PUT /product_index/product/2
{
"product_name": "Braun toothbrush 2000 3D",
"product_desc": "6 月 1 日 16 点秒杀,仅 329 元!限量 1000 支,抢完即止!带压力感应提醒,保护牙龈,高效清洁",
"price": 499.00,
"tags": [
"toothbrush",
"Braun"
]
}
PUT /product_index/product/3
{
"product_name": "iphone7 shell",
"product_desc": "一说到星空,就有太多美好的记忆,美丽的浩瀚宇宙,有太多说不清的神秘之处,星空太美丽,太绚烂!",
"price": 36.00,
"tags": [
"iphone7",
"phone",
"shell"
]
}
GET /product_index/product/_search
{
"aggs": {
"product_group_by_tags": {
"terms": {
"field": "tags"
}
}
}
}
GET /product_index/product/_search
{
"size": 0, ## 不显示 hits 原数据,只显示聚合统计结果
"aggs": {
"product_group_by_tags": {
"terms": {
"field": "tags"
}
}
}
}
{
"took": 9,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0,
"hits": []
},
"aggregations": {
"product_group_by_tags": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "toothbrush",
"doc_count": 2
},
{
"key": "braun",
"doc_count": 1
},
{
"key": "iphone7",
"doc_count": 1
},
{
"key": "philips",
"doc_count": 1
},
{
"key": "phone",
"doc_count": 1
},
{
"key": "shell",
"doc_count": 1
}
]
}
}
}
Fielddata is disabled on text fields by default. Set fielddata=true on [tags] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory.
PUT /product_index/_mapping/product
{
"properties": {
"tags": {
"type": "text",
"fielddata": true
}
}
}
GET /product_index/product/_search
{
"size": 0,
"query": {
"match": {
"product_name": "toothbrush"
}
},
"aggs": {
"query_product_group_by_tags": {
"terms": {
"field": "tags"
}
}
}
}
GET /product_index/product/_search
{
"size": 0,
"query": {
"match": {
"product_name": "toothbrush"
}
},
"aggs": {
"query_product_group_by_tags_and_avg": {
"terms": {
"field": "tags"
},
"aggs": {
"product_price_avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
GET /product_index/product/_search
{
"size": 0,
"query": {
"match": {
"product_name": "toothbrush"
}
},
"aggs": {
"query_product_group_by_tags_and_avg": {
"terms": {
"field": "tags",
"order": {
"product_price_avg_price": "desc"
}
},
"aggs": {
"product_price_avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
GET /product_index/product/_search
{
"size": 0,
"query": {
"match": {
"product_name": "toothbrush"
}
},
"aggs": {
"proudct_group_by_price": {
"range": {
"field": "price",
"ranges": [
{
"from": 0,
"to": 300
},
{
"from": 300,
"to": 400
},
{
"from": 400,
"to": 1000
}
]
},
"aggs": {
"product_group_by_tags": {
"terms": {
"field": "tags"
},
"aggs": {
"product_average_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
}
}
DELETE /product_index?pretty
PUT /product_index/product/1
{
"product_name": "PHILIPS toothbrush HX6730/02",
"product_desc": "【3?9 元,前 1000 名赠刷头,6 月 1 日 0 点火爆开抢,618 开门红巅峰 48 小时,抢先加入购物车】飞利浦畅销款,万千好评!深入净齿,智能美白!",
"price": 399.00,
"tags": [
"toothbrush",
"PHILIPS"
]
}
PUT /product_index/product/2
{
"product_name": "Braun toothbrush 2000 3D",
"product_desc": "6 月 1 日 16 点秒杀,仅 329 元!限量 1000 支,抢完即止!带压力感应提醒,保护牙龈,高效清洁",
"price": 499.00,
"tags": [
"toothbrush",
"Braun"
]
}
PUT /product_index/product2/1
{
"product_name": "Braun toothbrush 2000 3D type2",
"product_desc": "6 月 1 日 16 点秒杀,仅 329 元!限量 1000 支,抢完即止!带压力感应提醒,保护牙龈,高效清洁",
"price": 499.00,
"tags": [
"toothbrush",
"Braun"
]
}
PUT /product_index2/product2/2
{
"product_name": "iphone7 shell",
"product_desc": "一说到星空,就有太多美好的记忆,美丽的浩瀚宇宙,有太多说不清的神秘之处,星空太美丽,太绚烂!",
"price": 36.00,
"tags": [
"iphone7",
"phone",
"shell"
]
}
GET /_mget
{
"docs": [
{
"_index": "product_index",
"_type": "product",
"_id": 1
},
{
"_index": "product_index2",
"_type": "product2",
"_id": 1
}
]
}
GET /product_index/_mget
{
"docs": [
{
"_type": "product",
"_id": 1
},
{
"_type": "product2",
"_id": 1
}
]
}
GET /product_index/product/_mget
{
"ids": [1, 2]
}
POST /_bulk
{"delete": {"_index": "product_index","_type": "product","_id": "1"}}
POST /_bulk
{ "create": { "_index": "product_index", "_type": "product", "_id": "333" } }
{ "product_name": "iphone7 shell2", "product_desc": "一说到星空,就有太多美好的记忆,美丽的浩瀚宇宙,有太多说不清的神秘之处,星空太美丽,太绚烂!", "price": 36.00, "tags": [ "iphone7", "phone", "shell" ] }
POST /_bulk
{"update":{"_index": "product_index","_type": "product","_id": "1"}}
{"doc":{"product_name": "iphone7 shell2222"}}
DELETE /product_index?pretty
PUT /product_index/product/111
{
"product_name": "PHILIPS toothbrush HX6730/02",
"product_desc": "【3?9 元,前 1000 名赠刷头,6 月 1 日 0 点火爆开抢,618 开门红巅峰 48 小时,抢先加入购物车】飞利浦畅销款,万千好评!深入净齿,智能美白!",
"price": 399.00,
"tags": [
"toothbrush",
"PHILIPS"
]
}
PUT /product_index/product/222
{
"product_name": "PHILIPS toothbrush HX6730/02",
"product_desc": "【3?9 元,前 1000 名赠刷头,6 月 1 日 0 点火爆开抢,618 开门红巅峰 48 小时,抢先加入购物车】飞利浦畅销款,万千好评!深入净齿,智能美白!",
"price": 399.00,
"custom_version": 1,
"tags": [
"toothbrush",
"PHILIPS"
]
}
PUT /product_index/product/111?version=1
{
"product_name": "PHILIPS toothbrush HX6730/02 update1",
"product_desc": "【3?9 元,前 1000 名赠刷头,6 月 1 日 0 点火爆开抢,618 开门红巅峰 48 小时,抢先加入购物车】飞利浦畅销款,万千好评!深入净齿,智能美白!",
"price": 399.00,
"tags": [
"toothbrush",
"PHILIPS"
]
}
PUT /product_index/product/111?version=1
{
"product_name": "PHILIPS toothbrush HX6730/02 update2",
"product_desc": "【3?9 元,前 1000 名赠刷头,6 月 1 日 0 点火爆开抢,618 开门红巅峰 48 小时,抢先加入购物车】飞利浦畅销款,万千好评!深入净齿,智能美白!",
"price": 399.00,
"tags": [
"toothbrush",
"PHILIPS"
]
}
核心:
客户端 1 执行:
PUT /product_index/product/222?version=3&version_type=external
{
"product_name": "PHILIPS toothbrush HX6730/02 update3",
"product_desc": "【3?9 元,前 1000 名赠刷头,6 月 1 日 0 点火爆开抢,618 开门红巅峰 48 小时,抢先加入购物车】飞利浦畅销款,万千好评!深入净齿,智能美白!",
"price": 399.00,
"tags": [
"toothbrush",
"PHILIPS"
]
}
PUT /product_index/product/222?version=5&version_type=external
{
"product_name": "PHILIPS toothbrush HX6730/02 update5",
"product_desc": "【3?9 元,前 1000 名赠刷头,6 月 1 日 0 点火爆开抢,618 开门红巅峰 48 小时,抢先加入购物车】飞利浦畅销款,万千好评!深入净齿,智能美白!",
"price": 399.00,
"tags": [
"toothbrush",
"PHILIPS"
]
}