启动es docker run --name es6 --net host -e "discovery.type=single-node" docker.io/elasticsearch:6.5.4
es操作: 参考: ElasticSearch restful实操 www.cnblogs.com/gshao/p/110… 1、查询数据 curl -X GET "http://x.x.x.x:9200/_cat" curl -X GET http://x.x.x.x:9200/_cat/indices?v curl -X GET "http://x.x.x.x:9200/index01/_search?pretty"
2、操作数据demo
创建索引:
curl -X PUT http://x.x.x.x:9200/index01 同: put /index01
删除索引:
curl -XDELETE http://x.x.x.x:9200/index01
插入数据:
curl -XPOST http://x.x.x.x:9200/index01/type01 -H "Content-Type: application/json" \
-d '{"name" : "john","age" : 18,"id" : 2}'
同: POST /index01/type01
{"name" : "john"}
更新部分数据:
curl -XPOST http://x.x.x.x:9200/index01/type01/1/_update?pretty -H "Content-Type: application/json" \
-d '{"doc":{"name": "zhangsan"}}'
查询数据:
curl -XGET http://x.x.x.x:9200/index01/type01/_search?pretty
curl -XGET http://x.x.x.x:9200/index01/_search?pretty \
-d '{
"query": {
"match_all": {}
}
}'
同: GET /index01/type01/_search?pretty
{
"query": {
"match_all": {}
}
}
查询表达式:
示例1:
GET /index01/type01/_search?pretty
{
"query":{
"bool": {
"filter": {"range" : {"age": {"gt": 18}}}
}
}
}
示例2:
{
"bool": {
"match_all": {}
}
}
查询数据:
curl -XGET http://x.x.x.x:9200/business_waybill/factoring_waybill/_search?pretty
匹配日期范围
curl -XGET http://x.x.x.x:9200/business_bill/factoring_bill/_search?pretty -H "Content-Type: application/json" \
-d '{
"query": {
"bool": {
"must": [
{
"range": {
"settle_tm": {
"gte": "2022-01-01",
"lte": "2022-01-01"
}
}
}
]
}
}
}'
匹配字段
curl -XGET http://x.x.x.x:9200/business_bill/factoring_bill/_search?pretty -H "Content-Type: application/json" \
-d '{
"query": {
"bool": {
"must": [
{
"match": {
"carrier_company_no":"123"
}
}
]
}
}
}'
匹配日期范围和字段(写法一)
curl -XGET http://x.x.x.x:9200/business_bill/factoring_bill/_search?pretty -H "Content-Type: application/json" \
-d '{
"query": {
"bool": {
"must": [
{
"match": {
"carrier_company_no":"123"
}
},
{
"range": {
"settle_tm": {
"gte": "2022-01-01",
"lte": "2022-01-01"
}
}
}
]
}
}
}'
匹配日期范围和字段(写法二)
curl -XGET http://x.x.x.x:9200/business_bill/factoring_bill/_search?pretty -H "Content-Type: application/json" \
-d '{
"query": {
"bool": {
"must": [
{
"match": {
"carrier_company_no":"123"
}
}
],
"filter":{
"range": {
"settle_tm": {
"gte": "2022-01-01",
"lte": "2022-01-01"
}
}
}
}
}
}'
mapping操作
查看mapping
curl -XGET http://x.x.x.x:9200/business_bill?pretty
创建mapping,添加mapping字段和新加mapping一样的操作
curl -XPOST 'http://x.x.x.x:9200/business_bill/factoring_bill/_mapping?pretty' -H "Content-Type: application/json" \
-d '
{
"factoring_bill": {
"properties": {
"settle_tm": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"settle_no": {
"type": "text"
},
"amount_sum": {
"type": "double"
},
"carrier_company_no": {
"type": "text"
},
"carrier_company_name": {
"type": "text"
},
"settle_status": {
"type": "integer"
},
"waybill_no": {
"type": "text"
},
"business_dt": {
"type": "text"
},
"trans_job_item_code": {
"type": "text"
},
"charging_tm": {
"type": "text"
},
"volume": {
"type": "double"
},
"weight": {
"type": "double"
},
"count": {
"type": "double"
},
"amount": {
"type": "double"
}
}
}
}'