首页 文章 精选 留言 我的

精选列表

搜索[Elasticsearch],共4106篇文章
优秀的个人博客,低调大师

Elasticsearch之REST

REST 简介-定义 REST (REpresentation State Transfer)描述了一个架构样式的网络系统,比如 web 应用程序。它首次出现在 2000 年 Roy Fielding 的博士论文中,他是 HTTP 规范的主要编写者之一。REST 指的是一组架构约束条件和原则。满足这些约束条件和原则的应用程序或设计就是 RESTful。 Web 应用程序最重要的 REST 原则是,客户端和服务器之间的交互在请求之间是无状态的。从客户端到服务器的每个请求都必须包含理解请求所必需的信息。如果服务器在请求之间的任何时间点重启,客户端不会得到通知。此外,无状态请求可以由任何可用服务器回答,这十分适合云计算之类的环境。客户端可以缓存数据以改进性能。 在服务器端,应用程序状态和功能可以分为各种资源。资源是一个有趣的概念实体,它向客户端公开。资源的例子有:应用程序对象、数据库记录、算法等等。每个资源都使用 URI (Universal Resource Identifier) 得到一个惟一的地址。所有资源都共享统一的界面,以便在客户端和服务器之间传输状态。使用的是标准的 HTTP 方法,比如 GET、PUT、POST 和 DELETE。 REST 简介-资源 REST 简介-基本操作 1)GET 获取对象的当前状态 2)PUT 改变对象的状态 3)POST 创建对象 4)DELETE 删除对象 5)HEAD 获取头信息 REST 简介-资源 ES 内置的REST接口 本文转自大数据躺过的坑博客园博客,原文链接:http://www.cnblogs.com/zlslch/p/6617403.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

elasticsearch 多次聚合

curl -XGET 'http://localhost:9200/alias-product/product/_search?pretty' -d '{ "size" : 0, "query" : { "function_score" : { "query" : { "filtered" : { "filter" : { "bool" : { "should" : [ { "match" : { "_all" : { "query" : "电子", "type" : "boolean", "operator" : "AND" } } }, { "match" : { "company_name" : { "query" : "电子", "type" : "boolean", "operator" : "AND" } } }, { "match" : { "title" : { "query" : "电子", "type" : "boolean", "operator" : "AND" } } } ], "minimum_should_match" : "1" } } } }, "functions" : [ { "filter" : { "match" : { "_all" : { "query" : "电子", "type" : "boolean", "operator" : "AND" } } }, "weight" : 2.0 }, { "filter" : { "match" : { "company_name" : { "query" : "电子", "type" : "boolean", "operator" : "AND" } } }, "weight" : 8.0 }, { "filter" : { "match" : { "title" : { "query" : "电子", "type" : "boolean", "operator" : "AND" } } }, "weight" : 4.0 }, { "filter" : { "range" : { "seling_auction_cnt" : { "from" : 0, "to" : null, "include_lower" : false, "include_upper" : true } } }, "weight" : 1.0 }, { "field_value_factor" : { "field" : "company_score", "factor" : 1.0E-6 } } ], "score_mode" : "sum" } }, "aggs" : { "agg" : { "terms" : { "field" : "member_id", "size" : 0, "order" : { "top_hit" : "desc" } }, "aggregations" : { "top_hit" : { "max" : { "script" : { "inline" : "_score" } } } } }, "agg1" : { "scripted_metric": { "init_script": "_agg[\"prd\"] = []", "map_script": "if(doc[\"cat2_id\"].value) {_agg.prd.add(doc[\"cat2_id\"].value.toString())}", "combine_script": "combined = [:]; for (tmp in _agg.prd) { if(!combined[tmp]) { combined[tmp] = 1 } }; return combined", "reduce_script": "reduced = []; for (a in _aggs) { for (entry in a) { reduced.add(entry.key); } }; return reduced" } }, "agg2" : { "scripted_metric": { "init_script": "_agg[\"prd\"] = []", "map_script": "if(doc[\"cat2_id\"].value) {_agg.prd.add(doc[\"cat2_id\"].value.toString())}", "combine_script": "combined = [:]; for (tmp in _agg.prd) { if(!combined[tmp]) { combined[tmp] = 1 } }; return combined", "reduce_script": "reduced = [:]; for (a in _aggs) { for (entry in a) { word = entry.key; if (!reduced[word] ) { reduced[word] = entry.value; } } }; return reduced" } } } }' 本文转自whk66668888 51CTO博客,原文链接:http://blog.51cto.com/12597095/1908017

优秀的个人博客,低调大师

elasticsearch 前缀匹配

curl -XDELETE 'http://localhost:9200/ess/'; curl -XPOST 'http://localhost:9200/ess' -d '{ "analysis": { "filter": { "autocomplete_filter": { "type": "edge_ngram", "min_gram": 1, "max_gram": 20, "token_chars": ["whitespace"] } }, "analyzer": { "autocomplete": { "type": "custom", "tokenizer": "whitespace", "filter": [ "lowercase", "autocomplete_filter" ] }, "postsearch": { "tokenizer": "keyword", "filter": [ "lowercase" ] } } } }' curl -XPOST 'http://localhost:9200/ess/ess/_mapping' -d' { "ess": { "properties": { "id": { "type" : "long" }, "fullname": { "type" : "string" }, "allname": { "type" : "string", "analyzer": "autocomplete", "search_analyzer": "postsearch" } } } }' curl 'localhost:9200/ess/_analyze?pretty=1&analyzer=autocomplete' -d 'zs zhangsan zsan zhangs 张三 张s zns' curl 'localhost:9200/ess/_analyze?pretty=1&analyzer=postsearch' -d 'Z' curl -XPOST http://localhost:9200/ess/ess/1 -d' {"fullname":"张三" , "allname" : "zs zhangsan zsan zhangs 张三 张s zns" } ' curl -XPOST http://localhost:9200/ess/ess/2 -d' {"fullname":"张三风" , "allname" : "zsf zhangsanfeng zsanfeng zhangsf 张三 三风 张sf znsf" } ' curl -XPOST http://localhost:9200/ess/ess/3 -d' {"fullname":"李三风" , "allname" : "lsf lisanfeng lsanfeng lsf 李三 三风 李s lsf" } ' curl -XGET 'http://localhost:9200/ess/_search?pretty' -d '{ "query": { "match": { "allname": "张S" } } }' 本文转自whk66668888 51CTO博客,原文链接:http://blog.51cto.com/12597095/1903495

优秀的个人博客,低调大师

elasticsearch 排序 算法

如何将tfidf映射到[1,3] 区间内 (1)建立映射x→arctanx,此为一一映射,把全体实数R映射到开区间(-π/2,π/2)(2)开区间(-π/2,π/2)到开区间(0,1)只需要一个线性映射就可以,设为f(x)=ax+b,则有f(-π/2)=1且f(π/2)=3,解得a=2/π,b=2综合一下,映射x→2(arctanx)/π+2,即把全体实数映射到(1,3) 所以表达式可以写成 "script_score" : { "script" : "return atan(_score.doubleValue())*2/3.14159+2" } 为了只使用函数值 设置"boost_mode": "replace", 所以整个请求如下 curl -XGET 'http://localhost:9200/alias-product/product/_search?pretty&explain' -d '{ "size" : 1, "query" : { "function_score" : { "query" : { "bool" : { "should" : [ { "match" : { "_all" : { "query" : "关键字", "type" : "boolean", "operator" : "AND", "boost": 10 } } }, { "match" : { "company_name" : { "query" : "关键字", "type" : "boolean", "operator" : "AND", "boost": 10 } } } ], "minimum_should_match" : "1" } }, "functions" : [ { "script_score" : { "script" : "return atan(_score.doubleValue())*2/3.14159+2" } },{ "filter" : { "match" : { "company_name" : { "query" : "关键字", "type" : "boolean", "operator" : "AND" } } }, "weight" : 2 } ], "score_mode" : "sum", "boost_mode": "replace" } }, "aggregations" : { "agg" : { "terms" : { "field" : "member_id", "size" : 0, "order" : { "top_hit" : "desc" } }, "aggregations" : { "top_hit" : { "max" : { "script" : { "inline" : "_score" } } } } } } }' 本文转自whk66668888 51CTO博客,原文链接:http://blog.51cto.com/12597095/1942729

优秀的个人博客,低调大师

elasticsearch aggregation 缓存

在工作中遇到一个问题,按照6个维度进行聚合,响应校验,平均需要300ms。看了相关资料后,采用以下方式解决: 启用数据压缩 transport.tcp.compress: true 2. 使用缓存 curl -XPUT 'localhost:9200/yourIndex/_settings' -d' { "index.requests.cache.enable": true } ' 并设置缓存占JVM堆的大小 indices.requests.cache.size: 5% 最后在请求总加入 setRequestCache(true).setSearchType(SearchType.QUERY_THEN_FETCH); 注意,使用DFS_QUERY_THEN_FETCH 缓存不会生效。 最终响应时间在30ms,少了一个数量级。 本文转自whk66668888 51CTO博客,原文链接:http://blog.51cto.com/12597095/1947542

优秀的个人博客,低调大师

elasticsearch 特殊命令

重置备份 curl -XPUT "http://localhost:9200/_settings" -d' { "number_of_replicas" : 2 }' 2.安全关闭 curl -XPUT http://localhost:9200/_cluster/settings -d' { "transient" : { "cluster.routing.allocation.enable" : "none" } }' curl -XPUT http:// localhost:9200/_cluster/settings -d' { "transient" : { "cluster.routing.allocation.enable" : "all" } }' 3.关闭自动刷新 大批量插入之前 # curl -XPUT http://127.0.0.1:9200/company -d' { "settings" : { "refresh_interval": "-1" } }' 大批量插入之后改回1 4.索引别名 curl -XPOST 'http://localhost:9200/_aliases' -d ' { "actions": [ {"remove": {"index": "company", "alias": "company_alia"}}, {"add": {"index":"company ", "alias": " company_alia_bak"}} ] }' 5.手动分配分片 分配一个未分配的分片到指定节点。可以指定索引名和分片号。node参数指定分配到那个节点。allow_primary参数可以强制分配主分片,不过这样可能导致数据丢失。 curl -s "http://localhost:9200/_cat/shards" | grep UNASSIGNED curl 'localhost:9200/_nodes/process?pretty' curl -XPOST 'localhost:9200/_cluster/reroute' -d '{ "commands" : [ { "allocate" : { "index" : "your_index_name", "shard" : 1 (share index), "node" : "AfUyuXmGTESHXpwi4OExxx(NODE 编码)", "allow_primary" : true } } ] }' 本文转自whk66668888 51CTO博客,原文链接:http://blog.51cto.com/12597095/1903268

优秀的个人博客,低调大师

elasticsearch aggregation script

返回map "scripted_terms": { "scripted_metric": { "init_script": "_agg[\"prd\"] = []", "map_script": "if(doc[\"cat2_id\"].value) {_agg.prd.add(doc[\"cat2_id\"].value.toString())}", "combine_script": "combined = [:]; for (tmp in _agg.prd) { if(!combined[tmp]) { combined[tmp] = 1 } }; return combined", "reduce_script": "reduced = [:]; for (a in _aggs) { for (entry in a) { word = entry.key; if (!reduced[word] ) { reduced[word] = entry.value; } } }; return reduced" } } 返回array "scripted_terms": { "scripted_metric": { "init_script": "_agg[\"prd\"] = []", "map_script": "if(doc[\"cat2_id\"].value) {_agg.prd.add(doc[\"cat2_id\"].value.toString())}", "combine_script": "combined = [:]; for (tmp in _agg.prd) { if(!combined[tmp]) { combined[tmp] = 1 } }; return combined", "reduce_script": "reduced = []; for (a in _aggs) { for (entry in a) { reduced.add(entry.key); } }; return reduced" } } 统计求和 "agg1" : { "scripted_metric" : { "init_script" : { "inline" : "_agg[\"prd\"] = []" }, "map_script" : { "inline" : "if(doc[\"cat2_id\"].value) {_agg.prd.add(doc[\"cat2_id\"].value.toString())}" }, "combine_script" : { "inline" : "combined = [:]; for (tmp in _agg.prd) { if(!combined[tmp]) { combined[tmp] = 1 } else { combined[tmp]=combined[tmp]+1 } }; return combined" }, "reduce_script" : { "inline" : "reduced = [:]; for (a in _aggs) { for (entry in a) { word = entry.key; if (!reduced[word] ) { reduced[word] = entry.value; } else { reduced[word]=reduced[word]+entry.value} } }; return reduced" } } } 本文转自whk66668888 51CTO博客,原文链接:http://blog.51cto.com/12597095/1908014

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

用户登录
用户注册