这是我参与2022首次更文挑战的第2天,活动详情查看:2022首次更文挑战
Elasticsearch 以下简称:es
es 常见api操作
查看所有索引
http://${ip地址}/_cat/indices?v&pretty
查看索引的settings
http://${ip地址}/${索引名}/_settings
查看索引的mappings
http://${ip地址}/${索引名}/_mappings
查看索引分析器
http://${ip地址}/${索引名}/_analyze
// custom_analyzer 为自定义分词器。默认是:standard
{
"analyzer": "custom_analyzer",
"text": "饮水机"
}
查看分词结果
http://${ip地址}/${索引名}/${type}/${文档主键Id}/_termvectors?fields=${字段名}
根据索引搜索查看doc
http://${ip地址}/_search
{
"query": {
"bool": {
"should": [
{ "match": { "title": "" }},
{ "match": { "content": "员" }}
]
}
}
}
// 查询时间范围
{ "range": {
"time": {
"gte": "2021-12-01",
"lte": "2022-12-10"
}
}
}
// 精准查询 code为字段名称
"filter": [{
"term": {
"code": "chen"
}
}]
// 或者
"terms": {
"code": ["chen", "zhang"]
}
// 联合查询
"aggs": {
"message": {
"terms": {
"field": "comment"
}
}
}
批量更新
使用_bulk进行批量插入操作 使用 curl 运行文件
// es-master es服务器域名
curl -X POST "es-master:9200/\_bulk?pretty" -H 'Content-Type: application/json' --data-binary "@${文件名}"
使用 curl 运行
// es-master es服务器域名
curl -X POST "es-master:9200/_bulk?pretty" -H 'Content-Type: application/json' -d
// 文件最后需要拼接'结尾
持续更新中~~
特别感谢: