日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

painless语法入门[通俗易懂]

發布時間:2023/12/15 综合教程 26 生活家
生活随笔 收集整理的這篇文章主要介紹了 painless语法入门[通俗易懂] 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

大家好,又見面了,我是你們的朋友風君子。

painless語法

painless基礎結構


  "script": { 
   
    "lang":   "...",
    "source" | "id": "...",
    "params": { 
    ... }
  }
  1. lang: 定義腳本使用的語言, 默認painless
  2. source, id: 腳本的主體, source后面跟著內聯的腳本代碼, id后面跟著腳本的id, 具體代碼存在于腳本id對應的代碼中
  3. params: 定義一些變量的值, 使用params可以減少腳本的編譯次數. 因為如果變量的值硬編碼到代碼中, 每次進行變量值得更改都會對腳本進行重新編譯. 使用params則不會重新編譯腳本.

script.context.field.max_compilations_rate=75/5m 腳本的默認編譯頻率, 定義腳本的編譯頻率為5分鐘75個, 當超過75個時會拋出circuit_breaking_exception異常.

腳本代碼的存儲

// POST _scripts/{id}
POST _scripts/calculate-score
{ 

"script": { 

"lang": "painless",
"source": "Math.log(_score * 2) + params['my_modifier']"
}
}
// 腳本使用
GET my-index-000001/_search
{ 

"query": { 

"script_score": { 

"query": { 

"match": { 

"message": "some message"
}
},
"script": { 

"id": "calculate-score", 
"params": { 

"my_modifier": 2
}
}
}
}
}

使用腳本對文檔進行更新


PUT my-index-000001/_doc/1
{ 

"counter" : 1,
"tags" : ["red"]
}
// 將count加上4
POST my-index-000001/_update/1
{ 

"script" : { 

"source": "ctx._source.counter += params.count",
"lang": "painless",
"params" : { 

"count" : 4
}
}
}
// 增加tags的元素
POST my-index-000001/_update/1
{ 

"script": { 

"source": "ctx._source.tags.add(params['tag'])",
"lang": "painless",
"params": { 

"tag": "blue"
}
}
}
// If the list contains duplicates of the tag, this script just removes one occurrence.
// 如果集合中有多個相同的值, 只刪除第一個
POST my-index-000001/_update/1
{ 

"script": { 

"source": "if (ctx._source.tags.contains(params['tag'])) { ctx._source.tags.remove(ctx._source.tags.indexOf(params['tag'])) }",
"lang": "painless",
"params": { 

"tag": "blue"
}
}
}
// 增加新的字段
POST my-index-000001/_update/1
{ 

"script" : "ctx._source.new_field = 'value_of_new_field'"
}
// 刪除字段
POST my-index-000001/_update/1
{ 

"script" : "ctx._source.remove('new_field')"
}
// 如果tags字段中包含green, 則刪除該文檔, 否則不做操作
POST my-index-000001/_update/1
{ 

"script": { 

"source": "if (ctx._source.tags.contains(params['tag'])) { ctx.op = 'delete' } else { ctx.op = 'none' }",
"lang": "painless",
"params": { 

"tag": "green"
}
}
}
// doc.containsKey('field')

腳本變量

  • ctx._source.field: add, contains, remove, indexOf, length
  • ctx.op: The operation that should be applied to the document: index or delete
  • ctx._index: Access to document metadata fields
  • _score 只在script_score中有效
  • doc[‘field’], doc[‘field’].value: add, contains, remove, indexOf, length

腳本緩存

  1. You can change this behavior by using the script.cache.expire setting. Use the script.cache.max_size setting to configure the size of the cache.The size of scripts is limited to 65,535 bytes. Set the value of script.max_size_in_bytes to increase that soft limit.
  2. Cache sizing is important. Your script cache should be large enough to hold all of the scripts that users need to be accessed concurrently.

腳本優化

  1. 使用腳本緩存, 預先緩存可以節省第一次的查詢時間
  2. 使用ingest pipeline進行預先計算
  3. 相比于_source.field_name使用doc[‘field_name’]語法速度更快, doc語法使用doc value , 列存儲

// 根據分數相加結果進行排序
GET /my_test_scores/_search
{ 

"query": { 

"term": { 

"grad_year": "2099"
}
},
"sort": [
{ 

"_script": { 

"type": "number",
"script": { 

"source": "doc['math_score'].value + doc['verbal_score'].value"
},
"order": "desc"
}
}
]
}
// 在索引中新加一個字段存儲計算結果
PUT /my_test_scores/_mapping
{ 

"properties": { 

"total_score": { 

"type": "long"
}
}
}
// 使用ingest pipeline先將計算結果作為值存儲起來
PUT _ingest/pipeline/my_test_scores_pipeline
{ 

"description": "Calculates the total test score",
"processors": [
{ 

"script": { 

"source": "ctx.total_score = (ctx.math_score + ctx.verbal_score)"
}
}
]
}
// 重新索引時使用ingest pipeline
POST /_reindex
{ 

"source": { 

"index": "my_test_scores"
},
"dest": { 

"index": "my_test_scores_2",
"pipeline": "my_test_scores_pipeline"
}
}
// 索引新文檔時使用ingest pipeline
POST /my_test_scores_2/_doc/?pipeline=my_test_scores_pipeline
{ 

"student": "kimchy",
"grad_year": "2099",
"math_score": 1200,
"verbal_score": 800
}
// 查詢
GET /my_test_scores_2/_search
{ 

"query": { 

"term": { 

"grad_year": "2099"
}
},
"sort": [
{ 

"total_score": { 

"order": "desc"
}
}
]
}
// stored field 用法
PUT my-index-000001
{ 

"mappings": { 

"properties": { 

"full_name": { 

"type": "text",
"store": true
},
"title": { 

"type": "text",
"store": true
}
}
}
}
PUT my-index-000001/_doc/1?refresh
{ 

"full_name": "Alice Ball",
"title": "Professor"
}
GET my-index-000001/_search
{ 

"script_fields": { 

"name_with_title": { 

"script": { 

"lang": "painless",
"source": "params._fields['title'].value + ' ' + params._fields['full_name'].value"
}
}
}
}

用到腳本的命令

  • function_score
  • script_score
  • aggregation
  • rescore

總結

以上是生活随笔為你收集整理的painless语法入门[通俗易懂]的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲精品视频免费在线观看 | 黑人精品一区二区三区 | 免费看欧美黑人毛片 | 男人添女人下部高潮全视频 | 国产成人精品a视频一区 | 精品久久久无码中文字幕边打电话 | 横恋母在线观看 | 亚洲色图 欧美 | www视频免费观看 | 椎名由奈av一区二区三区 | 黑人无套内谢中国美女 | 用力抵着尿进去了h | 色屁屁影院www国产高清麻豆 | 日本视频色| 国模私拍大尺度裸体av | 人人超碰在线 | 极品新婚夜少妇真紧 | 欧美日韩国产一级 | 日本免费黄色网址 | 在线免费观看欧美大片 | 幸福宝在线观看 | 欧美日韩国产成人在线 | 国产 日韩 一区 | 国产无遮挡又黄又爽免费网站 | 五月天福利视频 | 免费在线观看污网站 | 国产在线观看免费视频软件 | 亚洲欧美日韩国产成人精品影院 | 正在播放一区二区 | 亚洲小视频网站 | 91在线小视频 | 日本午夜精品理论片a级app发布 | 68日本xxxxxⅹxxx22| 粉嫩av在线 | 成av人片一区二区三区久久 | 围产精品久久久久久久 | 久久精品噜噜噜成人88aⅴ | 少妇一级淫片免费播放 | 黄色小视频在线免费看 | 91国内精品久久久 | 黄色大片日本 | 中文字幕日韩经典 | 粉嫩aⅴ一区二区三区 | 精品国产va久久久久久久 | 国产麻豆剧传媒精品国产 | 朝桐光av在线一区二区三区 | www.五月婷婷.com | 成人性视频sm. | 精品三级 | 大牛影视剧免费播放在线 | 成人av地址| 日本做爰全过程免费看 | 奇米激情| 亚洲欧美一区二区精品久久久 | 一级特黄特色的免费大片视频 | 伊人91 | 中文字幕av一区二区三区人妻少妇 | 精品一卡二卡三卡 | 天天噜天天干 | 国产精品无码久久久久高潮 | 天天高潮夜夜爽 | 国产成人精品视频在线观看 | 一级黄色免费看 | 久久久久国产精品一区二区 | 青青草毛片 | 婷婷六月综合网 | 露胸app| 成人一级片在线观看 | 欧美日韩人妻精品一区在线 | 成人免费在线播放 | 国产精品国产三级国产aⅴ浪潮 | 亚洲欧美日韩在线一区二区 | 亚洲乱码久久 | 日本三级精品 | 亚洲一区精品在线观看 | 用力使劲高潮了888av | 欧美精品一区二区蜜臀亚洲 | 亚洲伦理一区二区 | 香蕉视频污视频 | 看片一区| 人体毛片| 视频区图片区小说区 | 国产成人一区二区三区电影 | 欧美日韩免费在线视频 | 天天爽夜夜爽夜夜爽 | 中文字幕免费在线观看 | 青青草成人在线 | 色婷婷色丁香 | 插我一区二区在线观看 | 精品五月天 | 久久人人爽人人爽人人片av高清 | 国产肉体ⅹxxx137大胆 | 国产亚洲一区二区三区在线观看 | 欧美色图13p | 影音先锋制服丝袜 | 99久免费精品视频在线观78 | 大学生av| 久久精品人妻一区二区三区 | 91吃瓜在线 |