ElastiSearch使用笔记
来源:互联网 发布:mac版pscc下载 编辑:程序博客网 时间:2024/05/20 11:24
在JS端使用elastic.js 处理
1.查询:
body = ejs.Request().query(ejs.QueryStringQuery("检索字符串").defaultOperator('AND')).highlight(ejs.Highlight('*'));//关键词检索
ejs.RegexpQuery(param.name,param.value) //正则表达式检索ejs.WildcardQuery(param.name,param.value);//通配符检索ejs.RangeQuery(param.name).from(param.from).to(param.to)//范围检索ejs.FuzzyQuery(param.name,param.value)//模糊检索ejs.PrefixQuery(param.name,param.value);//前缀匹配
esClient.search({ index:indices,//索引库的数组 type:types,//索引表的数组 body:body, size:99999},function(err,resp){ var result = resp.hits.hits;});
2.ajax查询
字段多条件: 字段名:值 and (or) 字段名:值 and(or)
queryStr += '字段名:\"'+值+'\" OR 字段名:值';
或者是拼装json
1、多条件,默认字段的
var queryData = {"query": {"bool": {"must": [{ "query_string": { "default_field": "dictionary.dictype", "query": "呵呵" }},{ "query_string": { "default_field": "dictionary.name", "query": "哈哈" } } }} };
2、使用文档ID作为条件的
queryData = "{\"query\": {\"bool\": {\"must\": [{\"query_string\": {\"default_field\": \"_id\",\"query\": \""+idTemp+"\"}}]}}}"
$.ajax({ url : "http://"+window.location.host+"/system/dictionary/_search", method : "post", dataType : "json", async:false, data : JSON.stringify(queryData),success : function(resp) { var hits = resp.hits.hits;});
3.更新
var t=form.serializeForm();esClient.update({index: index,type: type,id:id,refresh:true,body: {doc:t}}, function (error, response) {});
4.插入数据
esClient.create({ index: index, type: type, body: t, refresh:truefunction (error, response) {});
5.删除
esClient.delete({ index: index, type: type, id: id, refresh:true}, function (error, response) {});
6.统计
//select audit_keyword,count(*) as keyword_agg from operationlog group by operationlogesClient.search({searchType:'count',index:'user_operation_log',type:'operationlog',body:ejs.Request().agg(ejs.TermsAggregation('keyword_agg').field('audit_keyword'))},function(err,resp){aggResult=resp.aggregations.keyword_agg.buckets;//跟上面的TermsAggregation定义的名称对应});
0 0
- ElastiSearch使用笔记
- Elastisearch 笔记(curl命令)
- Java日记——使用强大的Elastisearch搜索引擎
- Elastisearch相关
- elastisearch搜索书名和作者
- 5. Elastisearch API CURD操作
- elastisearch之java api Transportclient创建连接
- 将ivy.xml中的elastisearch版本改成2.3.1然后ant编译后报错解决方案
- “印象笔记”使用笔记
- svn 使用笔记:客户端使用
- Mysql使用笔记
- emacs 使用笔记
- daab 3.1使用笔记
- BeanUtils使用笔记
- Win32函数使用笔记
- ASP.NET 使用笔记
- BeanUtils使用笔记
- CVS使用笔记
- 其他博客的资源
- IP地址获取到为0:0:0:0:0:0:0:1
- Ubuntu14.04安装搜狗输入法
- 文件上传 [bsp 1.1 ]
- 值得推荐的Android应用性能检测工具列表
- ElastiSearch使用笔记
- 【计算机硬件基础知识】指令系统基础
- 指尖菜谱App从0到1-项目初次开发
- 一些设计模式
- x86中断(一)-中断分类
- 在文件中查找单词及其行数
- 【php】Centos系统下Lamp环境的快速搭建
- C指针
- android 连续点击N次去执行某任务