批量造点数据
创建索引
PUT /my_store
{
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1
}
}
命令行形式:
curl -H "Content-Type: application/json" -XPUT 'http://10.24.54.241:9200/my_store' -d '{"settings" : {"number_of_shards" : 2,"number_of_replicas" : 1}}'
创建成功,如下图:
批量插入数据:
Kibana上运行的命令:
POST /my_store/products/_bulk
{ "index": { "_id": 1 }}
{ "price" : 10, "productID" : "XHDK-A-1293-#fJ3" }
{ "index": { "_id": 2 }}
{ "price" : 20, "productID" : "KDKE-B-9947-#kL5" }
{ "index": { "_id": 3 }}
{ "price" : 30, "productID" : "JODL-X-1937-#pV7" }
{ "index": { "_id": 4 }}
{ "price" : 30, "productID" : "QQPX-R-3956-#aD8" }
命令行窗口运行的命令:
curl -i -H "Content-Type: application/json" -XPOST 'http://10.24.54.241:9200/my_store/products/_bulk?pretty' --data-binary @bulk.json
DevTools
查询数据
命令如下:
GET /my_store/products/_search?pretty
curl -XGET 'http://10.24.54.241:9200/my_store/products/_search?pretty'
结果:
{
"took" : 67,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 4,
"max_score" : 1.0,
"hits" : [
{
"_index" : "my_store",
"_type" : "products",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"price" : 30,
"productID" : "JODL-X-1937-#pV7"
}
},
{
"_index" : "my_store",
"_type" : "products",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"price" : 10,
"productID" : "XHDK-A-1293-#fJ3"
}
},
{
"_index" : "my_store",
"_type" : "products",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"price" : 20,
"productID" : "KDKE-B-9947-#kL5"
}
},
{
"_index" : "my_store",
"_type" : "products",
"_id" : "4",
"_score" : 1.0,
"_source" : {
"price" : 30,
"productID" : "QQPX-R-3956-#aD8"
}
}
]
}
}
1、查找准确值
对于准确值,你需要使用过滤器。过滤器的重要性在于它们非常的快。
命令:
GET /my_store/products/_search
{
"query" : {
"bool" : {
"filter" : {
"term" : {
"price" : 20
}
}
}
}
}
curl命令行:
curl -H "Content-Type: application/json" -XPOST 'http://10.24.54.241:9200/my_store/products/_search?pretty' -d '
{
"query" : {
"bool" : {
"filter" : {
"term" : {
"price" : 20
}
}
}
}
}'
结果:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.0,
"hits" : [
{
"_index" : "my_store",
"_type" : "products",
"_id" : "2",
"_score" : 0.0,
"_source" : {
"price" : 20,
"productID" : "KDKE-B-9947-#kL5"
}
}
]
}
}