#创建 索引为blog 类型为article的文档
curl -H 'Content-Type:application/json' -XPUT http://localhost:9200/blog/article/1 -d '
{
"id": "1",
"title": "New version of Elasticsearch released!",
"content": "Version 1.0 released today!",
"priority": 10,
"tags": ["announce", "elasticsearch", "release"]
}'
curl -H 'Content-Type:application/json' -XPOST http://localhost:9200/blog/article/ -d '
{
"title": "Thress version of Elasticsearch released!",
"content": "Version 1.0 released today!",
"priority": 10,
"tags": ["announce", "elasticsearch", "release"]
}'
curl -H 'Content-Type:application/json' -XGET http://localhost:9200/blog/article/1?pretty
curl只想得到_source字段
curl -H 'Content-Type:application/json' -XGET http://localhost:9200/blog/article/1/_source
curl后加-i参数得到响应头
curl -H 'Content-Type:application/json' -i -XGET http://localhost:9200/blog/article/1?pretty
更新文档
curl -H 'Content-Type:application/json' -XPOST http://localhost:9200/blog/article/1/_update -d '{
"script": "ctx._source.content = \"new content\""
}'
创建mapping
curl -X PUT "localhost:9200/my_index" -H 'Content-Type: application/json' -d '{
"mappings": {
"my_maping": {
"properties": {
"title": {
"type": "text"
},
"content": {
"type": "text"
},
"priority": {
"type": "integer"
}
}
}
}
}'
写入数据 tags对应的mapping会自动创建
curl -H 'Content-Type:application/json' -XPUT http://localhost:9200/my_index/my_maping/2 -d '
{
"title": "New version of Elasticsearch released!",
"content": "Version 1.0 released today!",
"priority": 10,
"tags": ["announce", "elasticsearch", "release"]
}'
增加mapping字段
curl -H 'Content-Type:application/json' -XPUT http://localhost:9200/my_index/_mapping/my_maping -d '{
"properties": {
"attributeTags": {
"type": "nested",
"properties":{
"name":{"type":"keyword"},
"score":{"type":"double"}
}
}
}
}'
attributeTags: {
small: 0,
vulgarCode: 1,
black: 1,
quality: 0.79
}
获取mapping
curl -XGET “http://localhost:9200/my_index/_mapping?pretty”
获取数据
curl -H ‘Content-Type:application/json’ -i -XGET http://localhost:9200/my_index/my_maping/1?pretty
#插入数据
curl -H ‘Content-Type:application/json’ -XPUT http://localhost:9200/my_index/my_maping/3 -d ’
{
"title": "New version of Elasticsearch released!",
"content": "Version 1.0 released today!",
"priority": 10,
"tags": ["announce", "elasticsearch", "release"],
"attributeTags": {
"small": 0,
"vulgarCode": 1,
"black": 1,
"quality": 0.79
}
}'
查询数据
curl -H 'Content-Type:application/json' -i -XGET http://localhost:9200/my_index/my_maping/3?pretty
curl -H 'Content-Type:application/json' -XPUT http://localhost:9200/my_index/my_maping/4 -d '
{
"title": "New version of Elasticsearch released!",
"content": "Version 1.0 released today!",
"priority": 10,
"tags": ["announce", "elasticsearch", "release"],
"testTags": {
"small": 0,
"vulgarCode": 1,
"black": 1,
"quality": 0.79
}
}'
#自动创建的mapping
{
"my_index" : {
"mappings" : {
"my_maping" : {
"properties" : {
"attributeTags" : {
"type" : "nested",
"properties" : {
"black" : {
"type" : "long"
},
"name" : {
"type" : "keyword"
},
"quality" : {
"type" : "float"
},
"score" : {
"type" : "double"
},
"small" : {
"type" : "long"
},
"vulgarCode" : {
"type" : "long"
}
}
},
"content" : {
"type" : "text"
},
"priority" : {
"type" : "integer"
},
"tags" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"testTags" : {
"properties" : {
"black" : {
"type" : "long"
},
"quality" : {
"type" : "float"
},
"small" : {
"type" : "long"
},
"vulgarCode" : {
"type" : "long"
}
}
},
"title" : {
"type" : "text"
}
}
}
}
}
}
#查询es的setting
curl -H 'Content-Type:application/json' -i -XGET http://localhost:9200/my_index/_settings?pretty
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 334
{
"my_index" : {
"settings" : {
"index" : {
"creation_date" : "1567251792601",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "PY_GroItRk6YnHXNDEGilw",
"version" : {
"created" : "6040399"
},
"provided_name" : "my_index"
}
}
}
}
修改es的setting
curl -H 'Content-Type:application/json' -XPUT http://localhost:9200/my_index/_settings -d '{
"settings":
{"index.mapping.total_fields.limit": 2000}
}'
#查询es的setting
curl -H 'Content-Type:application/json' -i -XGET http://localhost:9200/my_index/_settings?pretty
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 334
{
"my_index" : {
"settings" : {
"index" : {
"creation_date" : "1567251792601",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "PY_GroItRk6YnHXNDEGilw",
"version" : {
"created" : "6040399"
},
"provided_name" : "my_index"
}
}
}
}
修改es的setting
curl -H 'Content-Type:application/json' -XPUT http://localhost:9200/my_index/_settings -d '{
"settings":
{"index.mapping.total_fields.limit": 2000}
}'
#更新数据
curl -H 'Content-Type:application/json' -XPOST 'localhost:9200/my_index/my_maping/6/_update ' -d '{
"script" : {
"inline": "ctx._source.attributeTestTags.add(attributeTestTag)",
"params" : {
"attributeTestTag" : [{"name": "quality","score":0.79}]
}
}
}'

1174

被折叠的 条评论
为什么被折叠?



