Elasticsearch–入门(二)
1,发送requestq请求到Elasticsearch
1.1,Curl方式
curl -u elastic:<password> localhost:9200/
1.2,Kibana方式
Kibana page > Dev Tools > Console
- 创建索引
PUT /my_goods_info
{
"mappings": {
"properties": {
"goodsName": {
"type": "keyword"
},
"sale_property": {
"type": "keyword"
},
"required_matches": {
"type": "long"
}
}
}
}
PUT my-products
{
"mappings": {
"properties": {
"brand": {
"type": "keyword"
},
"pt": {
"type": "date"
},
"name": {
"type": "keyword"
},
"color": {
"type": "keyword"
},
"price":{
"type":"integer"
}
}
}
}
- 查询数据
GET /my_goods_info/_search
{
"query": {
"terms_set": {
"sale_property": {
"terms": [
"white",
"64"
],
"minimum_should_match_field": "required_matches"
}
}
}
}
- 添加数据
PUT /my_goods_info/_doc/1?refresh
{
"name": "apple",
"sale_property": [ "white", "64","standard" ],
"required_matches": 2
}
- 批量插入数据
PUT my-products/_bulk
{"index":{"_id":1}}
{"brand":"nike","pt":"2021-01-01","name":"product_01","color":"red","price":600}
{"index":{"_id":2}}
{"brand":"grke","pt":"2021-02-01","name":"product_02","color":"red","price":200}
{"index":{"_id":3}}
{"brand":"lining","pt":"2021-03-01","name":"product_03","color":"green","price":300}
{"index":{"_id":4}}
{"brand":"lining","pt":"2021-02-01","name":"product_04","color":"green","price":450}
{"index":{"_id":5}}
{"brand":"grke","pt":"2021-04-01","name":"product_05","color":"blue","price":180}
{"index":{"_id":6}}
{"brand":"grke","pt":"2021-02-01","name":"product_06","color":"yellow","price":165}
{"index":{"_id":7}}
{"brand":"grke","pt":"2021-02-01","name":"product_07","color":"yellow":"price":190}
{"index":{"_id":8}}
{"brand":"lining","pt":"2021-04-01","name":"product_08","color":"blue","price":500}
{"index":{"_id":9}}
{"brand":"nike","pt":"2021-01-01","name":"product_09","color":"blue","price":1000}