Elasticsearch等的概述
Elasticsearch 总结
首先
只是一个总结(为了自己)。
终归总结不做,就无法理解。
即使已经有其他总结,但如果根据当时的环境进行整理,我相信自己亲自写总结是最好的。
- 知りたいこと検索とか そのあたり
环境
-
- macOS High Sierra
-
- Docker 19.03.5
-
- docker-compose 1.25.0
- Elasticsearch v6.8.3
数据
随意地放入。
这个问题
- 全検索
GET _search
{
"query": {
"match_all": {}
}
}
- indexを絞って検索
GET kibana_sample_data_ecommerce/_search
{
"query": {
"match_all": {}
}
}
- mappling
GET /library/_mappings
- フィールドの値一覧(keyword)
GET /library/_search
{
"size":0,
"aggs": {
"genre": {
"terms": {"field":"class.keyword"}
}
}
}
如果”type”不是关键字,则不需要添加关键字,但似乎需要列举数值。
回答
{
"took" : 8,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 7,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"genre" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "DVD",
"doc_count" : 3
},
{
"key" : "book",
"doc_count" : 2
},
{
"key" : "CD",
"doc_count" : 1
}
]
}
}
}
如果没有任何价值,就会被忽视。
- フィールドの値集計(最大・最小・平均)
GET /library/_search
{
"size": 0,
"query": {
"match": {
"class": "DVD"
}
},
"aggs": {
"max_price": {
"max": {
"field": "price"
}
},
"min_price": {
"min": {
"field": "price"
}
},
"average": {
"avg": {
"field": "price"
}
}
}
}
回复
{
"took" : 33,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 6,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"average" : {
"value" : 71.94999885559082
},
"max_price" : {
"value" : 125.94999694824219
},
"min_price" : {
"value" : 17.950000762939453
}
}
}
- 絞り込んだキーの一覧
GET /library/_search
{
"size":0,
"query": {
"match": {
"class": "DVD"
}
},
"aggs": {
"genre": {
"terms": {"field":"sub_class.keyword"
}
}
}
}
回复
{
"took" : 7,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 6,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"genre" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "animation",
"doc_count" : 2
},
{
"key" : "movie",
"doc_count" : 1
}
]
}
}
}
- and検索
GET /library/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"class": "DVD"
}
},
{
"match": {
"sub_class": "animation"
}
}
]
}
}
}
请参考
以下是一种可能的中文翻译:
https://qiita.com/nskydiving/items/1c2dc4e0b9c98d164329#mapping
https://medium.com/eureka-engineering/基础篇-深入掌握Elasticsearch的搜索查询-ace3e18c2174