es 学习 5 DSL mapping 使用 案例
2016-08-26 15:54
309 查看
<?php
别名修改 _aliases { "actions": [ { "remove": { "index": "index1", "alias": "index" } }, { "add": { "index": "index2", "alias": "index" } } ] }
{ "from": 0, "size": 20, "query": { "function_score": { "functions": [ { "gauss": { "created_at": { "origin": "2014/04/23 07:00:00",//何时开始 "scale": "2h",//控制 下降速度 缓慢,越大 下降越快 "offset": "10h"//偏移量 } }, "weight": 10 } ], "query": { "match": { "description": "bmw" } }, "score_mode": "multiply" } } } { "query": { "function_score": { "filter": { "bool": { "should": { "multi_match": { "query": "宝马", "fields": [ "title", "advertiser_name", "advertiser_name_title" ] } } } }, "functions": [ { "filter": { "match": { "advertiser_name_title": "宝马" } }, "weight": "60" }, { "filter": { "match": { "title": "bmw" } }, "weight": "40" }, { "filter": { "match": { "advertiser_name": "宝马" } }, "weight": "60" }, { "script_score": { "script": "_score*doc['date3'].value" } }, { "gauss": { "date": { "origin": "20160829", "scale": "10d", "offset": "5d", "decay": 0.5 } } } ], "score_mode": "sum" } } } // analyzer : ik_max_word ik_smart ik // search_analyzer : ik_max_word ik_smart ik // 近义词 配置 index 案例 { "mappings":{ "addata_index":{ "_all": { "search_analyzer": "ik_syno_smart", "analyzer": "ik_syno" }, "properties": { "id": { "type": "float" }, "width": { "include_in_all": true, "type": "string" }, "metas": { "type": "string", "include_in_all": true, "search_analyzer": "ik_syno_smart", "analyzer": "ik_syno" } } } } } // ik 中文 分词 配置 案例 { "mappings": { "addata_index": { "_all": { "search_analyzer": "ik_smart", "analyzer": "ik_max_word" }, "properties": { "id": { "type": "float" }, "width": { "include_in_all": false, "type": "string" }, "tracker_full": { "type": "string", "include_in_all": true, "search_analyzer": "ik_smart", "analyzer": "ik_max_word" }, "subject_rand": { "type": "float", "include_in_all": false } } } } } // DSL 案例 使用 // function_score 使用
// { // "query": { // "function_score": { // "filter": { // "bool": { // "must": [ // { // "multi_match": { // "query": "bmw", // "fields": [ // "advertiser_name", // "title", // "advertiser_name_title" // ] // } // } // ] // } // }, // "functions": [ // { // "filter": { // "match": { // "advertiser_name": "bmw" // } // }, // "weight": 100 // }, // { // "filter": { // "match": { // "title": "bmw" // } // }, // "weight": 99 // }, // { // "script_score": { // "script": "_score + doc['created_date'].value" // } // } // ], // "score_mode": "sum" // } // } // } $curl_param = [ 'from'=>$from, 'size'=>$size, 'query'=>[ 'function_score'=>[ 'filter'=>[ 'bool'=>[ 'should'=>[ 'multi_match'=>[ 'query'=>$param, // 'type'=>'cross_fields', // 'operator'=>'and', 'fields'=>[ 'title', 'name' ] ] ] ] ], 'functions'=>[ [ 'filter'=>[ 'match'=>[ 'title'=>$param ] ], "weight"=>'10' ], [ 'filter'=>[ 'match'=>[ 'name'=>$param ] ], "weight"=>'10' ], [ 'script_score'=>[ 'script'=>"_score*doc['created_date'].value" // 'script'=>"_score*doc['date2'].value" ] ] ], // 'score_mode'=>'first' ] ] ]; // multi_match 使用 $curl_param = [ 'from'=>$from, 'size'=>$size, 'query'=>[ 'multi_match'=>[ 'query'=>$param, 'type'=>'cross_fields', // 'type'=>'phrase', 'operator'=>'and', 'fields'=>[ 'name','title' //'name','title'//^4 ] ] ], // 'track_scores'=>true, // 'sort'=>[ // 'created_date'=>[ // 'order'=>'desc' // ] // ] "sort"=>[ [ '_script'=>[ 'script'=>"floor(doc['date2'].value)", 'type'=>'number', 'order'=>'desc' ] ], [ '_score'=>[ 'order'=>'desc' ] ] ] ]; // aggs 统计 数据 $curl_param = [ 'query'=>[ 'bool'=>[ 'must'=>[ 'term'=>[ 'id'=>$id ] ] ] ], 'aggs'=>[ 'first_detected'=>[ 'min'=>[ 'field'=>'created_date' ] ], 'last_detected'=>[ 'max'=>[ 'field'=>'created_date' ] ] ] ]; //多字段查询 $curl_param = [ 'sort'=>[ 'id'=>[ 'order'=>'desc' ] ], 'query'=>[ 'multi_match'=>[ 'query'=>$title, 'type'=>'best_fields', 'fields'=>[ 'title','domain','keywords' ], 'tie_breaker'=>0.3, 'minimum_should_match'=>'30%' ] ] ]; // range 使用 $curl_param = [ 'sort'=>[ 'id'=>'desc' ], 'query'=>[ 'filtered'=>[ 'filter'=>[ 'range'=>[ 'id'=>[ 'gte'=>$min_id, 'lte'=>$max_id ] ] ] ] ] ]; // group_by_state 使用 $curl_param = [ 'size'=>$size, 'query'=>[ 'bool'=>[ 'must'=>[ 'term'=>[ $field=>$value ] ], 'should'=>[ 'cname'=>$param ] ], ], 'aggs'=>[ 'group_by_state'=>[ 'terms'=>[ 'field'=>$groupBy ] ] ] ]; // sort 使用 $curl_param = [ 'size'=>$size, 'sort'=>[ 'date'=>[ 'order'=>'desc' ] ], 'query'=>[ 'bool'=>[ 'must'=>[ 'term'=>[ $field=>$value ] ], 'should'=>[ 'cname'=>$param ] ], ], 'aggs'=>[ 'group_by_state'=>[ 'terms'=>[ 'field'=>$groupBy ] ] ] ]; // sort 使用 多字段 // 只有满足第一个 条件时 才进行下一个条件排序 $curl_param = [ 'size'=>$size, 'sort'=>[ [ 'date'=>[ 'order'=>'desc' ] ], [ 'id'=>[ 'order'=>'desc' ] ] ], 'query'=>[ 'bool'=>[ 'must'=>[ 'term'=>[ $field=>$value ] ], 'should'=>[ 'cname'=>$param ] ], ], 'aggs'=>[ 'group_by_state'=>[ 'terms'=>[ 'field'=>$groupBy ] ] ] ];
相关文章推荐
- 转:一个学习案例: 使用 IBM Rational Unified Process 作为方法框架
- 案例学习BlazeDS+Spring之四InSync02使用RemoteObject事件
- 使用七牛云存储上传文件学习案例
- ES-MongoDB学习5_使用Mongo Connector和Elasticsearch实现模糊匹配
- iOS 学习笔记四 【xcode 7.3 ESJsonFormat-Xcode 插件不能使用的解决办法】
- 如何寻找使用案例及其注意事项,学习笔记
- C#之ArrayList的使用学习案例
- 第97讲:使用SBT开发Akka第一个案例环境搭建详解学习笔记
- JAVA学习笔记-----------InetAddress 的有关IP地址的使用案例(杂乱)
- ES学习(三)使用JDBC importer
- openGl-ES学习与使用心得-入门级
- 第七章 监听器listener单态登录使用案例学习心得
- oracle使用sql脚本生成csv文件案例学习
- Android(java)学习笔记245:ContentProvider使用(银行数据库创建和增删改查的案例)
- 【学习】Hadoop概念及使用案例
- 使用.net(C#)发送邮件学习手册(带成功案例
- [翻译]案例学习:仅使用Redis+PHP设计实现一个简单的Twitter
- 使用.net(C#)发送邮件学习手册(带成功案例)
- JAVA学习13_line.split("")的使用和解决ES接收数据不全的问题
- C#之一维数组的使用学习案例