Relational DB | ElasticSearch |
---|---|
数据库(database) | 索引(index) |
表(tables) | type |
行(rows) | documents |
字段(columns) | fields |
DELETE
注: 请求体必须换行
_bluk
POST http://{ip}:9200/customer/extenal/_bluk
{“操作”: “id”: “1”}
{“请求体”: " "}
例1:
{"index":{"id": "1"}}
{"name": "John"}
例2:
POST _bluk
# 删除语句
{"delete": {"index":"web", "_type": "blog", "id": "123"}}
# 创建语句
{"create": {"index":"web", "_type": "blog", "id": "123"}
{"title": "hello"}}
# 查询语句
{"index":{"index":"web", "_type": "blog", "id": "123"}
{"title": "hello"}}
# 更新语句
{"update": {"index":"web", "_type": "blog", "id": "123"}
{"doc": {"title": "hello"}}}
_search
# url+检索参数
GET bank/_search?q=*&sort=account_number: asc
# url+请求体
GET bank/_search
{"query":{"match":{}}},
"sort":[
{"account_number":"asc"}
]
① REST request URL (url+检索参数)
②REST request body (url+请求体)
“_source”: ["…", “…”] 返回指定字段
"multi_match": {"query": "......",
"fileds": ["adress": "......"]}
匹配字段包含fileds, query中所有字段
# 必须
"must": {"match":{
"gender": "F"
}},
"match": {{}}
# 必须不匹配
"must_not": {}
# 应该
"should": {}
不会计算相关性得分
注: keyword 精确值查询
如果查询的为非文本字段, 通常使用term
如果查询的是文本字段, 通常使用match
数组分组和提取数据的功能
相当于mysql中的GROUP_BY和SQL聚合
# 聚合语句
"aggregations": {
"" : {
"" : {
""
}
[,"meta": {["" ]}]?
[,"aggregations": {["" ]+}]?
},
""
}
# 例: 搜索address中包含mail的所有人的年龄分布以及平均年龄
GET bank/_search
{
"query": {
"match": {
"address": "mail"
}
},
"aggs": {
"aggAgg": {
"terms": {
"filed": "age",
"size": 10
}
},
"aggavg": {
"avg": {
"filed": "avg"
}
}
}
}
用来定义一个文档以及他所包含的属性filed是如何存储和索引的;
PUT /my_index
{"mappings":{
"properties":{
"age": {"type": "interger"}
"email": {"type": "keyword"}
}
}}
PUT /my_index/_mapping
{
"mappings": {
"properties": {
"" :{
"type": "keyword",
"index": False # index为True可以被检索,为False不能被检索
}
}
}
}
# 将老数据迁移到指定位置
POST _reindex
{
"_source":{
"index": "twitter"
},
"dest": {
"index": "new_twitter"
}
}
一个tokenizer(分词器)将之分割成独立的token
POST _analyse
{
"analyzer": "standard",
"text": "<需要做分词的文本内容>"
}
分词器词库: ik