簡(jiǎn)介
Elasticsearch 是一個(gè)分布式的免費(fèi)開(kāi)源搜索和分析引擎。適用于包括文本、數(shù)字于颖、地理空間迟几、結(jié)構(gòu)化和非結(jié)構(gòu)化數(shù)據(jù)等在內(nèi)的所有類(lèi)型的數(shù)據(jù)消请。
ES核心概念
關(guān)系型數(shù)據(jù)庫(kù)與ES對(duì)比
f1d69e27dd534fd1bbf8b93a094fcd59.png
新增文檔
指定文檔 id 創(chuàng)建文檔
20c49ab261db4653aa8aaae7f8602840.png
PUT /pt_emp_effect_info/_doc/888666
{
“emp_code”: “42014861”,
“emp_name”: “張三”
}
入庫(kù)結(jié)果
fbdd5d9c76da4de5aa83d2b14f35169a.png
自動(dòng)生成id
POST /pt_emp_effect_info/_doc
{
“emp_code”: “42014889”,
“emp_name”: “李四”
}
入庫(kù)結(jié)果
813d27ca9347450a87c999b86af727a7.png
修改文檔
指定id
POST /pt_emp_effect_info/_doc/42014889?refresh=true
{
“emp_code”: “42014889”,
“emp_name”: “李四”,
“emp_desc”: “描述”
}
刪除文檔
根據(jù)指定id刪除
DELETE /pt_emp_effect_info/_doc/888666
根據(jù)查詢(xún)條件刪除
POST /pt_emp_effect_info/_delete_by_query?refresh=true
{
“query”: {
“term” : {
“emp_code” : “42014889”
}
}
}
查詢(xún)文檔
查詢(xún)所有數(shù)據(jù)
GET /pt_emp_effect_info/_search
根據(jù)指定id查詢(xún)
GET /pt_emp_effect_info/_doc/42014889
詞條匹配(term)
term 查詢(xún)被用于精確值 匹配
POST /pt_emp_effect_info/_search
{
“query”: {
“**term**” : {
“emp_code” : “42014889”
}
}
}
多詞條精確匹配(terms)
POST /pt_emp_effect_info/_search
{
“query”: {
“**terms**” : {
“emp_code” : [“42014889”, “42011002”]
}
}
}
范圍查詢(xún) (gte lte gt lt)
POST /pt_emp_effect_info/_search
{
“query”: {
“**range**”: {
“create_time”: {
“gt”: “2023-07-18 00:00:00”
}
}
}
}
通配符
POST /pt_emp_effect_info/_search
{
“query”:{
“**wildcard**”:{
“emp_name”:“*張*”
}
}
}
指定輸出結(jié)果字段
POST /pt_emp_effect_info/_search
{
** “_source”: [“emp_code”],**
“query”: {
“term”: {
“emp_code”: “42014889”
}
}
}
組合查詢(xún)bool(must、must_not类腮、should梯啤、filter)
{
“_source”: [“waybill_no”, “deliver_tm”, “deliver_dept_code”],
“query”: {
“bool”: {
“must”: [
{
“exists”: {
“field”: “signed_back_is_pick”
}
}
],
“filter”: [
{
“range”: {
“deliver_tm”: {
“l(fā)te”: “2023-07-18 10:00:00”
}
}
},
{
“term”: {
“signed_back_is_need”: true
}
}
]
}
}
}
{
“bool”: {
“should”: [
{
“terms”: {
“a”: [
“a”
],
“boost”: 1
}
},
{
“terms”: {
“b”: [
“b”
],
“boost”: 1
}
}
],
“adjust_pure_negative”: true,
“minimum_should_match”: “1”,
“boost”: 1
}
}