Docs/ELK/es学习记录03-数据简单写入搜索.md
2022-10-18 16:59:37 +08:00

62 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#### 写入数据:
举例说明在索引名称未item中添加一个类型名称为es编号为3的数据
```
curl -XPUT 127.0.0.1:9200/item/es/3?pretty -H 'content-Type:application/json' -d '{"name": "bi", "age": 21}'
```
```
curl -XPOST 127.0.0.1:9200/item/es/3?pretty -H 'content-Type:application/json' -d '{"name": "bi", "age": 21}'
```
结果如下
```
{
"_index" : "item", ## 索引
"_type" : "es", ## 类型名称
"_id" : "3", ## 编号
"_version" : 1, ## 对该数据的第几次操作
"result" : "created", ## 因为之前没有,即创建
"_shards" : {
"total" : 2, ## 分片数
"successful" : 1, ## 分片成功次数
"failed" : 0 ## 分片失败数
},
"_seq_no" : 4, ## 序列编号
"_primary_term" : 1 ##
}
```
### get数据
```
curl -XGET 127.0.0.1:9200/item/es/3?pretty
```
结果为
```
{
"_index" : "item",
"_type" : "es",
"_id" : "3",
"_version" : 1,
"_seq_no" : 4,
"_primary_term" : 1,
"found" : true,
"_source" : {
"name" : "bi",
"age" : 21
}
}
```
### 搜索数据
```
curl -XGET 127.0.0.1:9200/item/es/_search?pretty
```
返回的结果方在hints数组中默认展示匹配到的前10条数据
### 精确搜索
```
curl -XGET 127.0.0.1:9200/item/es/_search?q=name:wang?pretty
```
```
curl -XGET 127.0.0.1:9200/item/es/_search?q=name:bi
```