创建索引:
格式如下:
PUT /索引名称
{
“settings”: { 配置信息},
“mappings”: {
“type名称”: {
"properties": {
“字段”:{"type":“字段类型”}
.......
}
}
}
示例:
PUT /test_index
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"test_type": {
"properties": {
"count": {
"type": "integer"
},
"title": {
"type": "keyword"
},
"content": {
"type": "text"
},
"createTime": {
"type": "text"
}
}
}
}
}
修改索引:
PUT /索引/type名称/_mapping
{
"type名称": {
"properties": {
“字段”:{"type":“字段类型”}
......
}
}
}
示例:
PUT /test_index/test_type/_mapping
{
"test_type": {
"properties": {
"count": {
"type": "integer"
},
"title": {
"type": "keyword"
},
"content": {
"type": "text"
}
}
}
}
数据插入 :
格式:
POST /索引/type名称
{
...数据内容...
}
示例
POST /test_index/test_type
{
"count": 10,
"title": "测试标题",
"content": "这是一个测试"
}
数据修改:
格式:
PUT /索引/type名称/数据的id
{
...数据内容...
}
示例
PUT /test_index/test_type/psWo_XIBgk8NUD3GDq9p
{
"count": 10,
"title": "测试标题",
"content": "这是一个测试(添加修改)"
}
删除:
删除响应文档
格式: DELETE /索引名称/type名称/数据的id
示例: DELETE /test_index/test_type/uqb_-HIBu2vUiLQfN6wu
删除所有索引 DELETE /_all
查询:
根据字段模糊查询(注意安装中文分词器):
格式:
GET /_search{
"query": {
"match" : {
"字段" : "字段值(可模糊匹配)"
}
}
}
示例:
GET /_search
{
"query": {
"match" : {
"content" : "测试"
}
}
}