GET _cat/indices
GET users/_doc/1
GET product/_search
- POST product/_update/1
-
- {
-
- "doc":{
-
- "price":899
-
- }
-
- }
- PUT product/_doc/1003
-
- {"title":"小米手机",
-
- "category":"小米",
-
- "price":"599",
-
- "image":"https://mi.jpg"
-
- }
DELETE product/_doc/1002
- GET shopping/_search
- {"query":{
- "match_phrase":{
- "image":"https://xiaomi.jpg"
- }
- }
- }
- GET product/_search
- {"query":{
- "match_all":{
-
- }},
- "from":0,
- "size":2,
- "_source":["brand","price"],
- "sort":{
- "price":{
- "order":"desc"
- }
- }
- }
- GET shopping/_search
- {
- "query":{
- "bool":{
- "must":[
- {"match":{
- "category": "小米"
- }},
- {"match":{
- "price": "599"
- }}
-
- ]
- }
- }
- }
- GET shopping/_search
- {
- "query":{
- "bool":{
- "should":[
- {"match":{
- "brandName": "小米"
- }},
- {"match":{
- "brandName": "vivo"
- }}
-
- ]
- }
- }
- }
- POST /user/_doc/1001
- {"name":"xiaomi",
- "sex":"F",
- "tel":"131"
- }
或
- PUT shopping/_create/1006
- {"title":"vivo手机",
- "category":"vivo",
- "price":"2958",
- "image":"https://vivo.jpg"
- }
- GET phone/_search
- {
- "aggs":{
- "price_group":{
- "terms":{
- "field":"price"
- }
- }
- },
- "size":0 //不显示原始数据
- }
- GET phone/_search
- {
- "aggs":{
- "price_avg":{
- "avg":{
- "field":"price"
- }
- }
- },
- "size":0 //不显示原始数据
- }
- GET gulimall_product/_search
- {
- "query": {
- "match_all": {}
-
- },
- "aggs": {
- "brand_agg": {
- "terms": {
- "field": "brandId",
- "size": 10
- },
- "aggs": {
- "brand_name_agg": {
- "terms": {
- "field": "brandName",
- "size": 10
- }
- }
- }
- },
- "catalog_agg":{
- "terms": {
- "field": "catalogId",
- "size": 10
- }
- }
- }
- }
- PUT gulimall_product
- {
- "mappings":{
- "properties": {
- "skuId":{ "type": "long" },
- "spuId":{ "type": "keyword" },
- "skuTitle": {
- "type": "text",
- "analyzer": "ik_smart"
- },
- "skuPrice": { "type": "keyword" },
- "skuImg" : { "type": "keyword" },
- "saleCount":{ "type":"long" },
- "hasStock": { "type": "boolean" },
- "hotScore": { "type": "long" },
- "brandId": { "type": "long" },
- "catalogId": { "type": "long" },
- "brandName": {"type": "keyword"},
- "brandImg":{
- "type": "keyword"
- },
- "catalogName": {"type": "keyword" },
- "attrs": {
- "type": "nested",
- "properties": {
- "attrId": {"type": "long" },
- "attrName": {
- "type": "keyword"
-
- },
- "attrValue": {"type": "keyword" }
- }
- }
- }
- }
- }
DELETE gulimall_product
在ElasticSearch中POST 可以创建ES自动生成id类型的document,也可自己指定id。
PUT id存在为创建,否则为全量替换。
另外PUT还可以 使用op_type=create或_create实行强制创建document。
ElasticSearch文档中字段类型一旦创建,便不能修改,需要修改时可先创建一个新的索引,在索引写好好映射结构,然后将上一个索引的数据迁移过去。