1.查看索引库的mapping
GET /my_index/my_type/_mapping
2.查看索引库的数据
GET /my_index/my_type/_search
3.es中创建后的mapping不可修改,但是可以添加新字段
PUT /my_index/_mapping/my_type
{
"properties": {
"new_field_name": {
"type": "keyword"
}
}
}
赋值:
POST my_index/_update_by_query
{
"script": {
"lang": "painless",
"inline": "ctx._source.new_field_name= '02'"
}
}
4.删除索引库
DELETE my_index
5. 分页查询,默认情况下查询一页十条数据
POST /_search
{
"size": 2,
"from": 10,
"query": {
"match_all": {}
}
}
size:表示每页显示多少条记录,form:表示从第几页开始显示记录
6.使用ik分词器分词
POST _analyze
{
"analyzer": "ik_max_word",
"text": "中国银行"
}
7.更新索引库中某个字段的值、
POST my_index/_update_by_query
{
"script": {
"lang": "painless",
"inline": "if(ctx._source.title== '李四'){ctx._source.title= '张三'}"
}
}
注释:将索引库my_index里面字段title值为李四的改为张三
8.直接向索引库添加数据
PUT /my_index/my_type/5
{
"title": "中国",
"content": "中国银行"
}
本文介绍了Elasticsearch中的关键操作,包括查看mapping、搜索数据、更新mapping、添加新字段、删除索引、分页查询、使用ik分词器及更新字段值等。通过实际示例,帮助读者掌握Elasticsearch的基本用法。
2183

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



