列出所有索引:
curl 'localhost:9200/_cat/indices?v'
# 删除索引
curl -XDELETE 'http://127.0.0.1:9200/res_center_1?pretty'
#获取映射
curl -XGET '10.124.134.206:9200/res_locking_number_his_1/_mapping?pretty'
# 构建索引 指定映射
curl -XPUT 'http://127.0.0.1:9200/res_ce_1118?pretty=true' -d '
{
"mappings" : {
"_default_": {
"_all": { "enabled": false }
},
"res_number" : {
"dynamic" : "strict",
"properties" : {
"PROVINCE_CODE" : {"type":"string","index":"not_analyzed"},
"B_AREA_CODE" : {"type":"string","index":"not_analyzed"},
"AREA_CODE" : {"type":"string","index":"not_analyzed"},
}
}
}
}
'
字段类型有下面的:
Core Simple Field Typesedit
Elasticsearch supports the following simple field types:
- String:
string
- Whole number:
byte
,short
,integer
,long
- Floating-point:
float
,double
- Boolean:
boolean
- Date:
date
https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping-intro.html#_viewing_the_mapping
# 别名
curl -XPUT 'http://127.0.0.1:9200/res_center_1/_alias/res_center?pretty=true'
# 检查字段映射
curl -XGET 'http://127.0.0.1:9200/res_center_1/_mapping/res_number?pretty=true'
curl -XGET 'http://127.0.0.1:9200/res_center/_mapping/res_number?pretty=true'
# 统计文档总数
curl -XGET 'http://127.0.0.1:9200/res_center/res_number/_search?pretty=true' -d '
{
"from" : 0, "size" : 10
}
'
# type增加属性
##这个可以使用
curl -XPUT 'http://127.0.0.1:9200/index/_mapping/type?pretty=true' -d '
{
"properties": {
"testField": {"type": "string","index":"not_analyzed"}
}
}'
添加一个document:
curl -PUT 'http://127.0.0.1:9200/index/type/14800002' -d '{
"DEVICE_NUMBER":"13701"
}'
修改一个document
curl -XPOST 'http://locahost:9200/index/type/14800002/_update' -d '{
"doc" : {
"name" : "new_name"
}
}
删除一个doc命令:
curl -XDELETE 'http://localhost:9200/index/type/13701019855'
参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html