Microservice微服务人生几何?

Elasticsearch学习笔记(一)

2021-08-31  本文已影响0人  dev_winner
es服务启动成功 Elasticsearch与MySQL的类比
# response
{
    "acknowledged": true, # 操作成功
    "shards_acknowledged": true, # 分片操作成功
    "index": "playing" #索引名称
}
{
    "error": {
        "root_cause": [
            {
                "type": "resource_already_exists_exception",
                "reason": "index [playing/2Rmw7bI-SZ-ntKHIbJGDoA] already exists",
                "index_uuid": "2Rmw7bI-SZ-ntKHIbJGDoA",
                "index": "playing"
            }
        ],
        "type": "resource_already_exists_exception",
        "reason": "index [playing/2Rmw7bI-SZ-ntKHIbJGDoA] already exists",
        "index_uuid": "2Rmw7bI-SZ-ntKHIbJGDoA",
        "index": "playing"
    },
    "status": 400
}
{
    "error": "Incorrect HTTP method for uri [/playing] and method [POST], allowed: [HEAD, DELETE, GET, PUT]",
    "status": 405
}
{
    "playing": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "creation_date": "1630457890587",
                "number_of_shards": "1",
                "number_of_replicas": "1",
                "uuid": "2Rmw7bI-SZ-ntKHIbJGDoA",
                "version": {
                    "created": "7060099"
                },
                "provided_name": "playing"
            }
        }
    }
}
health status index   uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   playing 2Rmw7bI-SZ-ntKHIbJGDoA   1   1          0            0       283b           283b
表头 含义
health 当前服务器健康状态:green(集群完整) yellow(单点正常、集群不完整) red(单点不正常)
status 索引打开、关闭状态
index 索引名
uuid 索引统一编号
pri 主分片数量
rep 副本数量
docs.count 可用文档数量
docs.deleted 文档删除状态(逻辑删除)
store.size 主分片和副分片整体占空间大小
pri.store.size 主分片占空间大小
{
    "acknowledged": true
}
{
    "error": {
        "root_cause": [
            {
                "type": "index_not_found_exception",
                "reason": "no such index [playing]",
                "resource.type": "index_or_alias",
                "resource.id": "playing",
                "index_uuid": "_na_",
                "index": "playing"
            }
        ],
        "type": "index_not_found_exception",
        "reason": "no such index [playing]",
        "resource.type": "index_or_alias",
        "resource.id": "playing",
        "index_uuid": "_na_",
        "index": "playing"
    },
    "status": 404
}
{
  "title":"一加phone",
  "category":"手机",
  "price":3999.00
}
{
    "_index": "playing",
    "_type": "_doc", #  类型-文档
    "_id": "ua3ynnsB4tbB67MkkEHa", #唯一标识
    "_version": 1, # 版本
    "result": "created", # 表示创建成功
    "_shards": {
        "total": 2, # 分片 - 总数
        "successful": 1, # 分片 - 成功
        "failed": 0 #分片 - 失败
    },
    "_seq_no": 0,
    "_primary_term": 1
}
{
    "error": "Incorrect HTTP method for uri [/playing/_doc] and method [PUT], allowed: [POST]",
    "status": 405
}
{
    "_index": "playing",
    "_type": "_doc",
    "_id": "1", # 自定义的id值
    "_version": 1,
    "result": "created",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 1,
    "_primary_term": 1
}
{
    "_index": "playing",
    "_type": "_doc",
    "_id": "1",
    "_version": 2,
    "result": "updated",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 2,
    "_primary_term": 1
}
{
    "_index": "playing",
    "_type": "_doc",
    "_id": "1",
    "_version": 3, # 改变
    "result": "updated",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 3, # 改变
    "_primary_term": 1
}
{
    "_index": "playing",
    "_type": "_doc",
    "_id": "1",
    "_version": 3,
    "_seq_no": 3,
    "_primary_term": 1,
    "found": true, # 表示找到
    "_source": { # 文档源信息
        "title": "一加phone",
        "category": "手机",
        "price": 3999
    }
}
{
    "_index": "playing",
    "_type": "_doc",
    "_id": "12",
    "found": false
}
{
    "took": 2763,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": 1,
        "hits": [
            {
                "_index": "playing",
                "_type": "_doc",
                "_id": "ua3ynnsB4tbB67MkkEHa",
                "_score": 1,
                "_source": {
                    "title": "一加phone",
                    "category": "手机",
                    "price": 3999
                }
            },
            {
                "_index": "playing",
                "_type": "_doc",
                "_id": "1",
                "_score": 1,
                "_source": {
                    "title": "一加phone",
                    "category": "手机",
                    "price": 3999
                }
            }
        ]
    }
}
{
  "title":"一加phone",
  "category":"手机",
  "price":4999.00 
}
{
    "_index": "playing",
    "_type": "_doc",
    "_id": "1",
    "_version": 4,
    "result": "updated",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 4,
    "_primary_term": 1
}
{
    "_index": "playing",
    "_type": "_doc",
    "_id": "1",
    "_version": 4,
    "_seq_no": 4,
    "_primary_term": 1,
    "found": true,
    "_source": {
        "title": "一加phone",
        "category": "手机",
        "price": 4999
    }
}
{
  "doc": {
    "title": "小米phone"
  }
}
{
    "_index": "playing",
    "_type": "_doc",
    "_id": "1",
    "_version": 5,
    "result": "updated",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 5,
    "_primary_term": 1
}
{
    "_index": "playing",
    "_type": "_doc",
    "_id": "1",
    "_version": 5,
    "_seq_no": 5,
    "_primary_term": 1,
    "found": true,
    "_source": {
        "title": "小米phone",
        "category": "手机",
        "price": 4999
    }
}
{
    "_index": "playing",
    "_type": "_doc",
    "_id": "1",
    "_version": 6,
    "result": "deleted",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 6,
    "_primary_term": 1
}
{
    "_index": "playing",
    "_type": "_doc",
    "_id": "1",
    "_version": 7,
    "result": "not_found", #找不到
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 7,
    "_primary_term": 1
}
{
    "took": 1251,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": 0.21072102,
        "hits": [
            {
                "_index": "playing",
                "_type": "_doc",
                "_id": "ua3ynnsB4tbB67MkkEHa",
                "_score": 0.21072102,
                "_source": {
                    "title": "一加phone",
                    "category": "手机",
                    "price": 3999
                }
            },
            {
                "_index": "playing",
                "_type": "_doc",
                "_id": "1",
                "_score": 0.21072102,
                "_source": {
                    "title": "一加phone",
                    "category": "手机",
                    "price": 3999
                }
            }
        ]
    }
}
{
    "query":{
        "match":{
            "category": "手机"
        }
    }
}
{
    "took": 22,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": 0.21072102,
        "hits": [
            {
                "_index": "playing",
                "_type": "_doc",
                "_id": "ua3ynnsB4tbB67MkkEHa",
                "_score": 0.21072102,
                "_source": {
                    "title": "一加phone",
                    "category": "手机",
                    "price": 3999
                }
            },
            {
                "_index": "playing",
                "_type": "_doc",
                "_id": "1",
                "_score": 0.21072102,
                "_source": {
                    "title": "一加phone",
                    "category": "手机",
                    "price": 3999
                }
            }
        ]
    }
}
{
    "query":{
        "match_all":{
            
        }
    },
    "from": 0,
    "size": 1
}
{
    "took": 9,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": 1,
        "hits": [
            {
                "_index": "playing",
                "_type": "_doc",
                "_id": "ua3ynnsB4tbB67MkkEHa",
                "_score": 1,
                "_source": {
                    "title": "一加phone",
                    "category": "手机",
                    "price": 3999
                }
            }
        ]
    }
}
{
    "query":{
        "match_all":{
            
        }
    },
    "from": 1,
    "size": 1,
    "_source": ["title"], #投影字段
    "sort": {
        "price": {
            "order": "desc"
        }
    }
}
{
    "took": 10,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": null,
        "hits": [
            {
                "_index": "playing",
                "_type": "_doc",
                "_id": "1",
                "_score": null,
                "_source": {
                    "title": "一加phone"
                },
                "sort": [
                    3999
                ]
            }
        ]
    }
}
{
    "query":{
        "bool": {
            "must": [ #表示 and 操作,必须同时满足
                {
                    "match": {
                        "category": "手机"
                    }
                }   
            ]
        }
    }
}
{
    "query":{
        "bool": {
            "should": [ #表示 or操作,只要符合条件都可以
                {
                    "match": {
                        "title": "小米"
                    }
                },
                {
                    "match": {
                        "title": "一加"
                    }
                }   
            ],
            "filter": { #按价格过滤
                "range": {
                    "price": {
                        "gt": 4000
                    }
                }
            }
        }
    }
}
{
    "took": 8,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": 1.3862942,
        "hits": [
            {
                "_index": "playing",
                "_type": "_doc",
                "_id": "2",
                "_score": 1.3862942,
                "_source": {
                    "title": "小米phone",
                    "category": "手机",
                    "price": 4999
                }
            }
        ]
    }
}
{
    "query":{
        "match_phrase": { #短词匹配,这里还能查询到估计是es分词了
            "title": "phone"
        }
    },
    "highlight": {
        "fields": {
            "title": {}
        }
    }
}
{
    "took": 9,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": 0.18232156,
        "hits": [
            {
                "_index": "playing",
                "_type": "_doc",
                "_id": "1",
                "_score": 0.18232156,
                "_source": {
                    "title": "一加phone",
                    "category": "手机",
                    "price": 3999
                },
                "highlight": {
                    "title": [
                        "一加<em>phone</em>"
                    ]
                }
            },
            {
                "_index": "playing",
                "_type": "_doc",
                "_id": "2",
                "_score": 0.18232156,
                "_source": {
                    "title": "小米phone",
                    "category": "手机",
                    "price": 4999
                },
                "highlight": {
                    "title": [
                        "小米<em>phone</em>"
                    ]
                }
            }
        ]
    }
}
{
    "aggs": { # 聚合操作
        "price_group": { #分组名
            "terms": { #分组操作
                "field": "price" #分组字段
            }
        }
    },
    "size": 0 # 不用返回原始数据
}
{
    "took": 146,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": null,
        "hits": [] # 对应上面的 size 字段值
    },
    "aggregations": {
        "price_group": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": 3999,
                    "doc_count": 1
                },
                {
                    "key": 4999,
                    "doc_count": 1
                }
            ]
        }
    }
}
{
    "aggs": {
        "price_avg": {
            "avg": {
                "field": "price"
            }
        }
    },
    "size": 0
}
{
    "took": 383,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "price_avg": {
            "value": 4499
        }
    }
}
{
    "properties": {
        "name":{
            "type": "text",
            "index": true
        },
        "sex":{
            "type": "keyword", # 表示完全匹配
            "index": true
        },
        "age":{
            "type": "long",
            "index": false # 表示不能被索引,也不能被查询
        }
    }
}
{
    "user": {
        "mappings": {
            "properties": {
                "age": {
                    "type": "long",
                    "index": false
                },
                "name": {
                    "type": "text"
                },
                "sex": {
                    "type": "keyword",
                    "index": true
                }
            }
        }
    }
}
上一篇 下一篇

猜你喜欢

热点阅读