创建文档
curl -XPUT --header "Content-Type:application/json" 'http://localhost:9200/cflog' -d '{
"settings":{
"number_of_shards":5
,"number_of_replicas":0
},
"mappings":{
"properties":{
"logtime":{
"type":"long"
}
,"level":{
"type":"keyword"
}
,"type":{
"type":"keyword"
}
,"cfno":{
"type":"text"
,"norms":false,"index_options":"freqs","analyzer":"whitespace"
}
,"threadname":{
"type":"keyword"
}
,"classname":{
"type":"keyword"
}
,"content":{
"type":"text"
,"norms":false,"index_options":"freqs","analyzer":"whitespace"
}
}
}
}'
清空索引数据
http://10.10.31.48:9200/
errorsummary/_delete_by_query?refresh post
{"query":{"match_all":{}}}
文档的格式是json式的。
对于文档,有几个主要的标识信息:_index(插入到哪个索引中),_type(插入到哪个类型中),_id(文档的id是多少),在插入一个文档的时候,这几个信息也是必须的。
插入文档
PUT /index/type/id
json格式的数据
_index:插入到哪个index中。
_type:插入到哪个type中。
_id:插入的文档的id是多少。
_version:版本,对这个ID的文档的操作次数
result:操作结果,第一次操作时created,上图中因为我忘记截图了,所以重新插入了一次,所以时updated
_shards:
total:总共有多少个shard
successful:成功多少个,【由于写操作只会发生在primary shard中,所以这里为1,另一个shard时replica shard,不发生写操作】
failed:失败多少个
查询指定文档
GET /index/type/id
更新文档
// 全替换(覆盖)式更新:会使用新的json数据直接覆盖原有的【请不要复制注释】
PUT /index/type/id
json数据
// 部分替换式更新:只会覆盖指定数据
POST /index/type/id/_update
{
"doc": {
"需要修改的字段": "修改值"
[,"需要修改的字段": "修改值"]
}
}
删除文档
DELETE /index/type/id
查询所有文档
GET /index/type/_search
{
"query":{
"match_all": {}
}
}