ELASTIC SEARCH 编辑
基本概念
索引_index/类型_type/文档_id
分片 备份
CRUD
写数据
http://192.168.32.140:9200/book/_search
{
"query": {
"match": {
"author": "五"
}
},
"sort": [
{"publish_date": {"order": "desc"}}
]
}
修改
- 直接修改文档
- 脚本修改文档
http://192.168.32.140:9200/people/man/1/_update
方法1,
{
“script”: {
“lang”: “painless”,
“inline”: “ctx._source.age +=5”
}
}
方法2.
{
“script”: {
“lang”: “painless”,
“inline”: “ctx._source.age = params.age” ,
“params”: {
“age”: “50”
}
}
}
删除/新建
新建index+table
// Sample1
http://192.168.32.140:9200/book
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1
},
"mappings": {
"man": {
"properties": {
"name": {
"type": "text"
},
"country": {
"type": "keyword"
},
"age": {
"type": "integer"
},
"date": {
"type": "date",
"format": "yyy-mm-dd HH:mm:ss||yyyy-mm-dd||epoch_millis"
}
}
}
}
}
//sample2
http://192.168.32.140:9200/book
{
"setting": {
"number_of_shards": 3,
"number_of_replicas": 1
},
"mappings": {
"book": {
"properties": {
"author": {
"type": "text"
},
"title": {
"type": "text"
},
"word_count": {
"type": "integer"
},
"publish_date": {
"type": "date",
"format": "yyy-mm-dd HH:mm:ss||yyyy-mm-dd||epoch_millis"
}
}
}
}
}
查询
高级查询/聚合查询(聚合查询可以多维度给出分析)
子条件查询 – 特定字段查询所指特定值
Query Context:
-
ES查询除判断文档是否满足查询条件,还会生成_score来表示匹配程度–用数字概率表示匹配
- 全文本查询 – 针对文本类型数据
- 字段级别查询 – 针对结构化数据 如 日期,数字
Filter Context
只判断文档是否满足条件YES/NO
复合条件查询
-
以一定的逻辑组合查询
- 固定分数查询
- 布尔查询