ElasticSearch6.0 高级应用之 多字段聚合Aggregation(二)
ElasticSearch6.0 多字段聚合网上完整的资料很少 ,所以作者经过查阅资料,编写了聚合高级使用例子
例子是根据电商搜索实际场景模拟出来的
希望给大家带来帮助!
下面我们开始吧!
1. 创建索引的映射关系
PUT gome_market
{
"mappings": {
"goods": {
"dynamic_templates": [
{
"dynamicFields": {
"match_mapping_type": "string",
"path_match":"dynamicFields.*_sku_attr",
"mapping":{
"type": "keyword"
}
}
}
],
"properties":{
"id":{
"type": "keyword"
},
"category_first_id":{
"type": "keyword"
},
"category_first":{
"type": "keyword"
},
"category_second_id":{
"type": "keyword"
},
"category_second":{
"type": "keyword"
},
"category_third_id":{
"type": "keyword"
},
"category_third":{
"type": "keyword"
},
"brand_id":{
"type": "keyword"
},
"brand":{
"type": "text",
"analyzer":"ik_max_word",
"search_analyzer":"ik_max_word",
"copy_to":"full_name"
},
"shop":{
"type": "keyword"
},
"attr_name":{
"type": "keyword",
"index":"true" },
"sku":{
"type": "keyword",
"index":"true"
},
"spu":{
"type": "keyword",
"index":"true"
},
"gome_sku":{
"type": "keyword"
},
"product_ch":{
"type": "text",
"analyzer":"ik_max_word",
"search_analyzer":"ik_max_word",
"copy_to":"full_name"
},
"adver":{
"type": "keyword"
},
"product_img":{
"type": "keyword"
},
"product_proto_price":{
"type": "double"
},
"product_sale_price":{
"type": "double"
},
"is_sku":{
"type": "boolean"
},
"is_self":{
"type": "boolean"
},
"shop_flag":{
"type": "long"
},
"is_in_store":{
"type": "boolean"
},
"is_shelves":{
"type": "boolean"
},
"is_suit":{
"type": "boolean"
},
"good_comment_rate":{
"type": "long"
},
"sale_num":{
"type": "long"
},
"spu_score":{
"type": "long"
},
"dynamic_attrs":{
"type": "keyword"
},
"full_name":{
"type": "text",
"store":"true"
},
"create_time":{
"type":"date"
}
}
}
}
}
2.创建索引数据
请参照上一篇文章
3.Controller层 创建 SuperMarketSearchController
package com.elastic.controller; import com.alibaba.fastjson.JSONObject; import com.elastic.service.inter.SuperMarketSearchService;
import com.elastic.service.pojo.SearchBean;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLDecoder;
import java.nio.charset.Charset; @Controller
public class SuperMarketSearchController extends BaseController { private static final Logger logger = Logger.getLogger(SuperMarketSearchController.class); @Resource(name = "superMarketSearchServiceImpl")
private SuperMarketSearchService searchService; @RequestMapping(value = "/s.action")
public String searchForPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
try {
String param = getParam(request);
logger.info("请求参数:" + param);
SearchBean bean = JSONObject.toJavaObject(JSONObject.parseObject(param), SearchBean.class);
bean.setQuery(bean.getQuery() != null ? URLDecoder.decode(bean.getQuery(), "UTF-8") : null);
String re = searchService.searchByBean(bean);
printReturnVal(response, re);
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
printReturnVal(response, assemReturn("[]", 500, "系统异常,请检查参数:" + e.getMessage()));
}
return null;
} @RequestMapping(value = "/suggest")
public void suggest(HttpServletRequest request, HttpServletResponse response) throws Exception {
String keyword = request.getParameter("keyword");
// String newKeyWord="";
// if (!StringUtils.isEmpty(keyword)){
// newKeyWord = new String(keyword.getBytes("ISO-8859-1"), "UTF-8");
// }
SearchBean bean = new SearchBean();
// bean.setQuery(newKeyWord==""?"********":newKeyWord);
bean.setQuery(keyword);
PrintWriter out = null;
String suggests = searchService.suggestByBean(bean);
printReturnVal(response, suggests);
} private void printReturnVal(HttpServletResponse response, String returnVal) {
PrintWriter out = null;
try {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
out = response.getWriter();
System.out.println(returnVal);
out.print(returnVal);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
} private String getParam(HttpServletRequest request) throws IOException {
StringBuffer sb = new StringBuffer();
InputStream is = request.getInputStream();
InputStreamReader isr = new InputStreamReader(is, Charset.forName("UTF-8"));
BufferedReader br = new BufferedReader(isr);
String s = "";
while ((s = br.readLine()) != null) {
sb.append(s);
}
isr.close();
br.close();
String str = sb.toString();
logger.info("requstParam=" + str);
String param = "";
JSONObject jsonObject = JSONObject.parseObject(str);
if (jsonObject.getString("body") != null && !jsonObject.getString("body").isEmpty()) {
param = jsonObject.getString("body");
} else {
param = str;
}
return param;
} }
4. Service层 interface SuperMarketSearchService
package com.elastic.service.inter; import com.elastic.service.pojo.SearchBean; public interface SuperMarketSearchService { public String searchByBean(SearchBean bean); public String suggestByBean(SearchBean bean); }
Service层 Impl 实现 SuperMarketSearchServiceImpl
package com.elastic.service.impl; import com.elastic.common.conn.EsClient;
import com.elastic.service.inter.SuperMarketSearchService;
import com.elastic.service.pojo.Filter;
import com.elastic.service.pojo.SearchBean;
import com.elastic.service.vo.SearchParams;
import com.elastic.service.vo.SearchReturn;
import com.elastic.util.SpringApplicationUtils;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.Operator;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
import org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.search.aggregations.*;
import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter;
import org.elasticsearch.search.aggregations.bucket.range.Range;
import org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.terms.*;
import org.springframework.stereotype.Service; import java.math.BigDecimal;
import java.util.*;
import java.util.function.BiConsumer; import static org.elasticsearch.index.query.QueryBuilders.functionScoreQuery; /**
* Created by xiaotian on 2017/12/23.
*/
@Service
public class SuperMarketSearchServiceImpl implements SuperMarketSearchService { private EsClient esClient; @Override
public String searchByBean(SearchBean bean) {
try {
esClient = SpringApplicationUtils.getBean(EsClient.class);
SearchRequestBuilder searchRequestBuilder = esClient.getConnection().prepareSearch("gome_market").setTypes("goods");
long s = System.currentTimeMillis(); bean.setIsFacet(bean.getIsFacet() == null ? true : bean.getIsFacet());
if (bean.getIsFacet()){
//聚合
String[] attrFacet = new String[]{"attr_name"};
bean.setFacetFields(attrFacet); }
SearchResponse searchResponse = assemQueryByBean(searchRequestBuilder, esClient, bean); bean.setFacetFields(null);
if (bean.getIsFacet()){
String[] docAttrFields = getDocAttrFields(searchResponse);
bean.setFacetFields(docAttrFields);
SearchRequestBuilder requestBuilder = esClient.getConnection().prepareSearch("gome_market").setTypes("goods");
SearchResponse response = assemQueryByBean(requestBuilder, esClient, bean); Aggregations aggregations = response.getAggregations();
Map<String, Aggregation> asMap = aggregations.getAsMap();
List<String> list = new ArrayList<>();
for (String key: bean.getFacetFields()) {
InternalFilter filter = aggregations.get(key);
Map<String, Aggregation> aggMap = filter.getAggregations().getAsMap();
Iterator<String> iterator = filter.getAggregations().getAsMap().keySet().iterator();
while (iterator.hasNext()){
String keys = iterator.next();
if ("range".equals(keys)){
continue;
}
if (aggMap.get(keys)==null|| aggMap.get(keys) instanceof UnmappedTerms){
continue;
}
StringTerms aggregation = (StringTerms)aggMap.get(keys);
aggregation.getBuckets().forEach(bucket -> {
System.out.println(keys+"-->"+bucket.getKey()+":"+bucket.getDocCount());
list.add(keys+"-->"+bucket.getKey()+":"+bucket.getDocCount());
}); }
}
System.out.println("list="+list); Range range = response.getAggregations().get("range"); range.getBuckets().forEach(bucket ->{ System.out.println(String.format("key [%s], from [%s], to [%s], doc_count [%d]", bucket.getKey(), bucket.getFrom(),bucket.getTo(),bucket.getDocCount())); });
}else { } } catch (Exception e) {
e.printStackTrace();
} finally {
} return null;
} private String[] getDocAttrFields(SearchResponse searchResponse) {
List<String> attrFieldList = new ArrayList<>();
attrFieldList.add("category_third");
attrFieldList.add("category_third_id");
if (searchResponse.getAggregations().get("attr_name")!=null){
InternalFilter aggFilter= searchResponse.getAggregations().get("attr_name");
Map<String, Aggregation> aggMap = aggFilter.getAggregations().getAsMap();
Iterator<String> iterator = aggFilter.getAggregations().getAsMap().keySet().iterator();
while (iterator.hasNext()){
String keys = iterator.next();
StringTerms aggregation = (StringTerms)aggMap.get(keys);
aggregation.getBuckets().forEach(bucket -> {
attrFieldList.add("dynamicFields."+bucket.getKey()+"");
System.out.println(keys+"-->"+bucket.getKey()+":"+bucket.getDocCount());
}); }
} return attrFieldList.toArray(new String[attrFieldList.size()]);
} @Override
public String suggestByBean(SearchBean bean) {
return null;
} private SearchResponse assemQueryByBean(SearchRequestBuilder searchRequest, EsClient esClient, SearchBean bean) throws Exception { Map<String, Object> params = new HashMap<>();
params.put("num1", 1);
params.put("num2", 2); //String inlineScript = "long age;if (doc['age'].value < 45) age = doc['age'].value + 50; return age * params.num1;";
String inlineScript = " return doc['age'].value * params.num1;";
// + "return (diff +num1+num2)";
Script script = new Script(ScriptType.INLINE,"painless",inlineScript , params);
ScriptScoreFunctionBuilder scriptScoreFunctionBuilder = ScoreFunctionBuilders.scriptFunction(script);
//searchRequest.setQuery(functionScoreQuery(QueryBuilders.matchQuery("name","中华").operator(Operator.AND),scriptScoreFunctionBuilder));
searchRequest.setQuery(bean.getQuery()!=null?QueryBuilders.matchQuery("full_name",bean.getQuery()):QueryBuilders.matchAllQuery()); BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
//条件
boolQueryBuilder.must(queryBuilder);
//动态添加聚合项目
if (bean.getFacetFields()!=null){ for (String field : bean.getFacetFields()) {
TermsAggregationBuilder aggFieldBuilder = AggregationBuilders.terms(field).field(field);
aggFieldBuilder.size(1000);
AggregationBuilder filter = AggregationBuilders.filter(field, boolQueryBuilder);
filter.subAggregation(aggFieldBuilder);
searchRequest.addAggregation(filter);
}
} RangeAggregationBuilder rangeAggregationBuilder = AggregationBuilders.range("range").field("product_sale_price").addRange(0, 30).addRange(30,50).addRange(50,100);
searchRequest.addAggregation(rangeAggregationBuilder);
searchRequest.setPostFilter(boolQueryBuilder);
searchRequest.setFrom(0);
searchRequest.setSize(10);
searchRequest.setExplain(true);
System.out.println("param:"+searchRequest);
SearchResponse searchResponse = searchRequest.get();
return searchResponse; } private QueryBuilder getFilterQuery(String fieldName, Object[] fieldValues, String andor, BoolQueryBuilder queryBuilder) {
//BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); for (int i = 0; i < fieldValues.length; i++) {
if ("OR".equals(andor)){
queryBuilder.should(QueryBuilders.matchQuery(fieldName,fieldValues[i]).operator(Operator.OR));
}else if ("AND".equals(andor)){
queryBuilder.must(QueryBuilders.matchQuery(fieldName,fieldValues[i]).operator(Operator.AND));
}
} return queryBuilder; } private void assemQueryParam(SearchBean bean, SearchReturn returns) {
SearchParams params = new SearchParams();
params.setKeyword(bean.getQuery());
Filter f = bean.getFilter();
if (f != null) {
String[] catFirst = f.getCatFirst();
String[] catSecond = f.getCatSecond();
String[] catThird = f.getCatThird();
Integer[] brand = f.getBrand();
Integer[] country = f.getCountry();
String[] fgCatFirst = f.getFgCatFirst();
String[] fgCatSecond = f.getFgCatSecond();
String[] fgCatThird = f.getFgCatThird();
String[] whiteShopIds = f.getWhiteShopIds();
String[] whiteCateIds = f.getWhiteCateIds();
String[] whiteBrandIds = f.getWhiteBrandIds();
String[] whiteProdIds = f.getWhiteProdIds();
String[] blackShopIds = f.getBlackShopIds();
String[] blackCateIds = f.getBlackCateIds();
String[] blackBrandIds = f.getBlackBrandIds();
String[] blackProdIds = f.getBlackProdIds();
String[] activityIds = f.getActivityIds(); if (catFirst != null && catFirst.length > 0) {
params.setCatFirst(catFirst);
}
if (catSecond != null && catSecond.length > 0) {
params.setCatSecond(catSecond);
}
if (catThird != null && catThird.length > 0) {
params.setCatThird(catThird);
}
if (fgCatFirst != null && fgCatFirst.length > 0) {
params.setFgCatFirst(fgCatFirst);
}
if (fgCatSecond != null && fgCatSecond.length > 0) {
params.setFgCatSecond(fgCatSecond);
}
if (fgCatThird != null && fgCatThird.length > 0) {
params.setFgCatThird(fgCatThird);
}
if (brand != null && brand.length > 0) {
params.setBrand(brand);
}
if (country != null && country.length > 0) {
params.setCountry(country);
}
if (activityIds!=null&&activityIds.length>0){
params.setActivityIds(activityIds);
}
}
returns.setSearchParams(params);
}
}
5.通过kibana查询结果
查询条件 : 跟java执行是一样的参数
GET gome_market/_search
{
"from" : 0,
"size" : 10,
"query" : {
"match" : {
"full_name" : {
"query" : "多颜色多版本",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : true,
"lenient" : false,
"zero_terms_query" : "NONE",
"boost" : 1.0
}
}
},
"post_filter" : {
"bool" : {
"must" : [
{
"bool" : {
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"explain" : true,
"aggregations" : {
"category_third" : {
"filter" : {
"bool" : {
"must" : [
{
"bool" : {
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"aggregations" : {
"category_third" : {
"terms" : {
"field" : "category_third",
"size" : 1000,
"min_doc_count" : 1,
"shard_min_doc_count" : 0,
"show_term_doc_count_error" : false,
"order" : [
{
"_count" : "desc"
},
{
"_key" : "asc"
}
]
}
}
}
},
"category_third_id" : {
"filter" : {
"bool" : {
"must" : [
{
"bool" : {
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"aggregations" : {
"category_third_id" : {
"terms" : {
"field" : "category_third_id",
"size" : 1000,
"min_doc_count" : 1,
"shard_min_doc_count" : 0,
"show_term_doc_count_error" : false,
"order" : [
{
"_count" : "desc"
},
{
"_key" : "asc"
}
]
}
}
}
},
"dynamicFields.sku级多选_sku_attr" : {
"filter" : {
"bool" : {
"must" : [
{
"bool" : {
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"aggregations" : {
"dynamicFields.sku级多选_sku_attr" : {
"terms" : {
"field" : "dynamicFields.sku级多选_sku_attr",
"size" : 1000,
"min_doc_count" : 1,
"shard_min_doc_count" : 0,
"show_term_doc_count_error" : false,
"order" : [
{
"_count" : "desc"
},
{
"_key" : "asc"
}
]
}
}
}
},
"dynamicFields.sku级枚举_sku_attr" : {
"filter" : {
"bool" : {
"must" : [
{
"bool" : {
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"aggregations" : {
"dynamicFields.sku级枚举_sku_attr" : {
"terms" : {
"field" : "dynamicFields.sku级枚举_sku_attr",
"size" : 1000,
"min_doc_count" : 1,
"shard_min_doc_count" : 0,
"show_term_doc_count_error" : false,
"order" : [
{
"_count" : "desc"
},
{
"_key" : "asc"
}
]
}
}
}
},
"dynamicFields.品牌_sku_attr" : {
"filter" : {
"bool" : {
"must" : [
{
"bool" : {
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"aggregations" : {
"dynamicFields.品牌_sku_attr" : {
"terms" : {
"field" : "dynamicFields.品牌_sku_attr",
"size" : 1000,
"min_doc_count" : 1,
"shard_min_doc_count" : 0,
"show_term_doc_count_error" : false,
"order" : [
{
"_count" : "desc"
},
{
"_key" : "asc"
}
]
}
}
}
},
"dynamicFields.类别-模板2使用_sku_attr" : {
"filter" : {
"bool" : {
"must" : [
{
"bool" : {
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"aggregations" : {
"dynamicFields.类别-模板2使用_sku_attr" : {
"terms" : {
"field" : "dynamicFields.类别-模板2使用_sku_attr",
"size" : 1000,
"min_doc_count" : 1,
"shard_min_doc_count" : 0,
"show_term_doc_count_error" : false,
"order" : [
{
"_count" : "desc"
},
{
"_key" : "asc"
}
]
}
}
}
},
"dynamicFields.颜色-模板2使用_sku_attr" : {
"filter" : {
"bool" : {
"must" : [
{
"bool" : {
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"aggregations" : {
"dynamicFields.颜色-模板2使用_sku_attr" : {
"terms" : {
"field" : "dynamicFields.颜色-模板2使用_sku_attr",
"size" : 1000,
"min_doc_count" : 1,
"shard_min_doc_count" : 0,
"show_term_doc_count_error" : false,
"order" : [
{
"_count" : "desc"
},
{
"_key" : "asc"
}
]
}
}
}
},
"range" : {
"range" : {
"field" : "product_sale_price",
"ranges" : [
{
"from" : 0.0,
"to" : 30.0
},
{
"from" : 30.0,
"to" : 50.0
},
{
"from" : 50.0,
"to" : 100.0
}
],
"keyed" : false
}
}
}
}
查询结果:
{
"took": 9,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 4.531806,
"hits": [
{
"_shard": "[gome_market][0]",
"_node": "WBp9VADzRG2Jr-yIKi8h6w",
"_index": "gome_market",
"_type": "goods",
"_id": "100253641",
"_score": 4.531806,
"_source": {
"is_shelves": false,
"shop_flag": 2,
"category_third": "536_耳机/耳麦",
"shop": "",
"product_ch": "zyl-多颜色多版本",
"spu_score": 0,
"category_second": "311_时尚数码",
"category_third_id": "536",
"id": "100253641",
"is_in_store": false,
"sku": "100253641",
"brand": "10000073_诺基亚(NOKIA)",
"is_self": false,
"is_suit": false,
"product_proto_price": 0,
"create_time": "2017-12-25T07:20:37.510Z",
"good_comment_rate": 0,
"sale_num": 0,
"adver": "",
"attr_name": [
"品牌_sku_attr",
"颜色-模板2使用_sku_attr",
"类别-模板2使用_sku_attr",
"sku级枚举_sku_attr",
"sku级多选_sku_attr"
],
"category_first_id": "286",
"is_sku": true,
"dynamicFields": {
"品牌_sku_attr": [
"诺基亚(NOKIA)"
],
"颜色-模板2使用_sku_attr": [
"黑色"
],
"适用人群-模板2使用_sku_attr": [
"人群"
],
"类别-模板2使用_sku_attr": [
"手提包, 洗漱包"
]
},
"brand_id": 10000073,
"product_img": "//gfs17.atguat.net.cn/T1.FKTBvVT1RCvBVdK",
"product_sale_price": 2223,
"category_first": "286_数码",
"shop_id": "null",
"category_second_id": "311",
"gome_sku": "1000101403",
"spu": "9010006069"
},
"_explanation": {
"value": 4.531806,
"description": "sum of:",
"details": [
{
"value": 0.9293165,
"description": "weight(full_name:多 in 0) [PerFieldSimilarity], result of:",
"details": [
{
"value": 0.9293165,
"description": "score(doc=0,freq=2.0 = termFreq=2.0\n), product of:",
"details": [
{
"value": 0.6931472,
"description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details": [
{
"value": 1,
"description": "docFreq",
"details": []
},
{
"value": 2,
"description": "docCount",
"details": []
}
]
},
{
"value": 1.3407203,
"description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details": [
{
"value": 2,
"description": "termFreq=2.0",
"details": []
},
{
"value": 1.2,
"description": "parameter k1",
"details": []
},
{
"value": 0.75,
"description": "parameter b",
"details": []
},
{
"value": 11,
"description": "avgFieldLength",
"details": []
},
{
"value": 12,
"description": "fieldLength",
"details": []
}
]
}
]
}
]
},
{
"value": 0.6682933,
"description": "weight(full_name:颜 in 0) [PerFieldSimilarity], result of:",
"details": [
{
"value": 0.6682933,
"description": "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
"details": [
{
"value": 0.6931472,
"description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details": [
{
"value": 1,
"description": "docFreq",
"details": []
},
{
"value": 2,
"description": "docCount",
"details": []
}
]
},
{
"value": 0.96414346,
"description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details": [
{
"value": 1,
"description": "termFreq=1.0",
"details": []
},
{
"value": 1.2,
"description": "parameter k1",
"details": []
},
{
"value": 0.75,
"description": "parameter b",
"details": []
},
{
"value": 11,
"description": "avgFieldLength",
"details": []
},
{
"value": 12,
"description": "fieldLength",
"details": []
}
]
}
]
}
]
},
{
"value": 0.6682933,
"description": "weight(full_name:色 in 0) [PerFieldSimilarity], result of:",
"details": [
{
"value": 0.6682933,
"description": "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
"details": [
{
"value": 0.6931472,
"description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details": [
{
"value": 1,
"description": "docFreq",
"details": []
},
{
"value": 2,
"description": "docCount",
"details": []
}
]
},
{
"value": 0.96414346,
"description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details": [
{
"value": 1,
"description": "termFreq=1.0",
"details": []
},
{
"value": 1.2,
"description": "parameter k1",
"details": []
},
{
"value": 0.75,
"description": "parameter b",
"details": []
},
{
"value": 11,
"description": "avgFieldLength",
"details": []
},
{
"value": 12,
"description": "fieldLength",
"details": []
}
]
}
]
}
]
},
{
"value": 0.9293165,
"description": "weight(full_name:多 in 0) [PerFieldSimilarity], result of:",
"details": [
{
"value": 0.9293165,
"description": "score(doc=0,freq=2.0 = termFreq=2.0\n), product of:",
"details": [
{
"value": 0.6931472,
"description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details": [
{
"value": 1,
"description": "docFreq",
"details": []
},
{
"value": 2,
"description": "docCount",
"details": []
}
]
},
{
"value": 1.3407203,
"description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details": [
{
"value": 2,
"description": "termFreq=2.0",
"details": []
},
{
"value": 1.2,
"description": "parameter k1",
"details": []
},
{
"value": 0.75,
"description": "parameter b",
"details": []
},
{
"value": 11,
"description": "avgFieldLength",
"details": []
},
{
"value": 12,
"description": "fieldLength",
"details": []
}
]
}
]
}
]
},
{
"value": 0.6682933,
"description": "weight(full_name:版 in 0) [PerFieldSimilarity], result of:",
"details": [
{
"value": 0.6682933,
"description": "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
"details": [
{
"value": 0.6931472,
"description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details": [
{
"value": 1,
"description": "docFreq",
"details": []
},
{
"value": 2,
"description": "docCount",
"details": []
}
]
},
{
"value": 0.96414346,
"description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details": [
{
"value": 1,
"description": "termFreq=1.0",
"details": []
},
{
"value": 1.2,
"description": "parameter k1",
"details": []
},
{
"value": 0.75,
"description": "parameter b",
"details": []
},
{
"value": 11,
"description": "avgFieldLength",
"details": []
},
{
"value": 12,
"description": "fieldLength",
"details": []
}
]
}
]
}
]
},
{
"value": 0.6682933,
"description": "weight(full_name:本 in 0) [PerFieldSimilarity], result of:",
"details": [
{
"value": 0.6682933,
"description": "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
"details": [
{
"value": 0.6931472,
"description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details": [
{
"value": 1,
"description": "docFreq",
"details": []
},
{
"value": 2,
"description": "docCount",
"details": []
}
]
},
{
"value": 0.96414346,
"description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details": [
{
"value": 1,
"description": "termFreq=1.0",
"details": []
},
{
"value": 1.2,
"description": "parameter k1",
"details": []
},
{
"value": 0.75,
"description": "parameter b",
"details": []
},
{
"value": 11,
"description": "avgFieldLength",
"details": []
},
{
"value": 12,
"description": "fieldLength",
"details": []
}
]
}
]
}
]
}
]
}
},
{
"_shard": "[gome_market][1]",
"_node": "WBp9VADzRG2Jr-yIKi8h6w",
"_index": "gome_market",
"_type": "goods",
"_id": "1000122353",
"_score": 0.2876821,
"_source": {
"is_shelves": false,
"shop_flag": 2,
"category_third": "536_耳机/耳麦",
"shop": "",
"product_ch": "诺基亚(NOKIA)C5-05手机(黑银色)非定制机-------9010006069这个product改的",
"spu_score": 0,
"category_second": "311_时尚数码",
"category_third_id": "536",
"id": "1000122353",
"is_in_store": true,
"sku": "1000122353",
"brand": "10000073_诺基亚(NOKIA)",
"is_self": false,
"is_suit": false,
"product_proto_price": 0,
"create_time": "2017-12-25T07:20:36.931Z",
"good_comment_rate": 0,
"sale_num": 0,
"adver": "%E7%99%BD%E6%8B%BF009%20%E6%B1%89%E5%AD%97",
"attr_name": [
"品牌_sku_attr",
"颜色-模板2使用_sku_attr",
"类别-模板2使用_sku_attr",
"sku级枚举_sku_attr",
"sku级多选_sku_attr"
],
"category_first_id": "286",
"is_sku": true,
"dynamicFields": {
"sku级枚举_sku_attr": [
"洁厕剂"
],
"sku级多选_sku_attr": [
"中端高性价比"
],
"品牌_sku_attr": [
"诺基亚(NOKIA)"
],
"cy-屏幕尺寸_sku_attr": [
"测试测试"
],
"0122-cy-多选使用_sku_attr": [
"手柄可折叠"
],
"0121-cy-枚举使用_sku_attr": [
"1千米"
],
"0121-cy-多选使用_sku_attr": [
"5ml及以下"
],
"product级枚举_sku_attr": [
"可组合"
],
"product级描述_sku_attr": [
"测试"
]
},
"brand_id": 10000073,
"product_img": "//gfs11.atguat.net.cn/T1jzhTByY_1RCvBVdK",
"product_sale_price": 1311,
"category_first": "286_数码",
"shop_id": "null",
"category_second_id": "311",
"gome_sku": "1000046768",
"spu": "9010006069"
},
"_explanation": {
"value": 0.2876821,
"description": "sum of:",
"details": [
{
"value": 0.2876821,
"description": "weight(full_name:色 in 0) [PerFieldSimilarity], result of:",
"details": [
{
"value": 0.2876821,
"description": "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
"details": [
{
"value": 0.2876821,
"description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details": [
{
"value": 1,
"description": "docFreq",
"details": []
},
{
"value": 1,
"description": "docCount",
"details": []
}
]
},
{
"value": 1,
"description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details": [
{
"value": 1,
"description": "termFreq=1.0",
"details": []
},
{
"value": 1.2,
"description": "parameter k1",
"details": []
},
{
"value": 0.75,
"description": "parameter b",
"details": []
},
{
"value": 26,
"description": "avgFieldLength",
"details": []
},
{
"value": 26,
"description": "fieldLength",
"details": []
}
]
}
]
}
]
}
]
}
},
{
"_shard": "[gome_market][3]",
"_node": "WBp9VADzRG2Jr-yIKi8h6w",
"_index": "gome_market",
"_type": "goods",
"_id": "1000122354",
"_score": 0.2876821,
"_source": {
"is_shelves": false,
"shop_flag": 2,
"category_third": "536_耳机/耳麦",
"shop": "",
"product_ch": "诺基亚(NOKIA)C5-05手机(黑红色)searchadmin",
"spu_score": 0,
"category_second": "311_时尚数码",
"category_third_id": "536",
"id": "1000122354",
"is_in_store": true,
"sku": "1000122354",
"brand": "10000073_诺基亚(NOKIA)",
"is_self": false,
"is_suit": false,
"product_proto_price": 0,
"create_time": "2017-12-25T07:20:38.606Z",
"good_comment_rate": 0,
"sale_num": 0,
"adver": "%E9%95%BF%E6%9C%9F%E4%BF%83%E9%94%80%E8%AF%AD",
"attr_name": [
"品牌_sku_attr",
"颜色-模板2使用_sku_attr",
"类别-模板2使用_sku_attr",
"sku级枚举_sku_attr",
"sku级多选_sku_attr"
],
"category_first_id": "286",
"is_sku": true,
"dynamicFields": {
"品牌_sku_attr": [
"诺基亚(NOKIA)"
],
"颜色-模板2使用_sku_attr": [
"黑色"
],
"适用人群-模板2使用_sku_attr": [
"人群"
],
"类别-模板2使用_sku_attr": [
"马夹包, 腰挂, 手提包, 洗漱包, 化妆包, 折叠包, 其他"
]
},
"brand_id": 10000073,
"product_img": "//gfs17.atguat.net.cn/T1hNJTB5Av1RCvBVdK",
"product_sale_price": 849,
"category_first": "286_数码",
"shop_id": "null",
"category_second_id": "311",
"gome_sku": "1000046769",
"spu": "9010006069"
},
"_explanation": {
"value": 0.2876821,
"description": "sum of:",
"details": [
{
"value": 0.2876821,
"description": "weight(full_name:色 in 0) [PerFieldSimilarity], result of:",
"details": [
{
"value": 0.2876821,
"description": "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
"details": [
{
"value": 0.2876821,
"description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details": [
{
"value": 1,
"description": "docFreq",
"details": []
},
{
"value": 1,
"description": "docCount",
"details": []
}
]
},
{
"value": 1,
"description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details": [
{
"value": 1,
"description": "termFreq=1.0",
"details": []
},
{
"value": 1.2,
"description": "parameter k1",
"details": []
},
{
"value": 0.75,
"description": "parameter b",
"details": []
},
{
"value": 17,
"description": "avgFieldLength",
"details": []
},
{
"value": 17,
"description": "fieldLength",
"details": []
}
]
}
]
}
]
}
]
}
}
]
},
"aggregations": {
"dynamicFields.sku级枚举_sku_attr": {
"doc_count": 3,
"dynamicFields.sku级枚举_sku_attr": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "洁厕剂",
"doc_count": 1
}
]
}
},
"dynamicFields.类别-模板2使用_sku_attr": {
"doc_count": 3,
"dynamicFields.类别-模板2使用_sku_attr": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "手提包, 洗漱包",
"doc_count": 1
},
{
"key": "马夹包, 腰挂, 手提包, 洗漱包, 化妆包, 折叠包, 其他",
"doc_count": 1
}
]
}
},
"category_third_id": {
"doc_count": 3,
"category_third_id": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "536",
"doc_count": 3
}
]
}
},
"category_third": {
"doc_count": 3,
"category_third": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "536_耳机/耳麦",
"doc_count": 3
}
]
}
},
"dynamicFields.sku级多选_sku_attr": {
"doc_count": 3,
"dynamicFields.sku级多选_sku_attr": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "中端高性价比",
"doc_count": 1
}
]
}
},
"dynamicFields.品牌_sku_attr": {
"doc_count": 3,
"dynamicFields.品牌_sku_attr": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "诺基亚(NOKIA)",
"doc_count": 3
}
]
}
},
"range": {
"buckets": [
{
"key": "0.0-30.0",
"from": 0,
"to": 30,
"doc_count": 0
},
{
"key": "30.0-50.0",
"from": 30,
"to": 50,
"doc_count": 0
},
{
"key": "50.0-100.0",
"from": 50,
"to": 100,
"doc_count": 0
}
]
},
"dynamicFields.颜色-模板2使用_sku_attr": {
"doc_count": 3,
"dynamicFields.颜色-模板2使用_sku_attr": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "黑色",
"doc_count": 2
}
]
}
}
}
}
ElasticSearch6.0 高级应用之 多字段聚合Aggregation(二)的更多相关文章
- C# 6 与 .NET Core 1.0 高级编程 - 37 章 ADO.NET
译文,个人原创,转载请注明出处,有不对的地方欢迎指出与交流. 英文原文:Professional C# 6 and .NET Core 1.0 - 37 ADO.NET --------------- ...
- C# 6 与 .NET Core 1.0 高级编程 - 38 章 实体框架核心(上)
译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 38 章 实体框架核心(上)),不对的地方欢迎指出与交流. 章节出自<Professional C# 6 ...
- C# 6 与 .NET Core 1.0 高级编程 - 41 ASP.NET MVC(中)
译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 41 ASP.NET MVC(中)),不对的地方欢迎指出与交流. 章节出自<Professional C# ...
- ElasticSearch6.0 Java API 使用 排序,分组 ,创建索引,添加索引数据,打分等(一)
ElasticSearch6.0 Java API 使用 排序,分组 ,创建索引,添加索引数据,打分等 如果此文章对你有帮助,请关注一下哦 1.1 搭建maven 工程 创建web工程 ...
- elasticsearch 多字段聚合或者对字段子串聚合
以下是字段子串聚合,截取 'your_field' 前八位进行聚合的 Script script = new Script("doc['your_field'].getValue().sub ...
- Yii2.0高级框架数据库增删改查的一些操作(转)
yii2.0框架是PHP开发的一个比较高效率的框架,集合了作者的大量心血,下面通过用户为例给大家详解yii2.0高级框架数据库增删改查的一些操作 --------------------------- ...
- Yii2.0高级框架数据库增删改查的一些操作
yii2.0框架是PHP开发的一个比较高效率的框架,集合了作者的大量心血,下面通过用户为例给大家详解yii2.0高级框架数据库增删改查的一些操作 --------------------------- ...
- C# 6 与 .NET Core 1.0 高级编程 - 38 章 实体框架核心(下)
译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 38 章 实体框架核心(下)),不对的地方欢迎指出与交流. 章节出自<Professional C# 6 ...
- C# 6 与 .NET Core 1.0 高级编程 - 39 章 Windows 服务(上)
译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 39 章 Windows 服务(上)),不对的地方欢迎指出与交流. 章节出自<Professional C ...
随机推荐
- Swap交换分区--continue
Linux内核为了提高读写效率与速度,会将文件在内存中进行缓存,这部分内存就是Cache Memory(缓存内存).即使你的程序运行结束后,Cache Memory也不会自动释放.这就会导致你在Lin ...
- Django学习笔记之Cookie、Session和自定义分页
cookie Cookie的由来 大家都知道HTTP协议是无状态的. 无状态的意思是每次请求都是独立的,它的执行情况和结果与前面的请求和之后的请求都无直接关系,它不会受前面的请求响应情况直接影响,也不 ...
- Python学习笔记之函数参数传递 传值还是传引用
在学完Python函数那一章节时,很自然的的就会想到Python中函数传参时传值呢?还是传引用?或者都不是? 在回答上面的问题之前我们先来看看下面的代码: 代码1: def foo(var): v ...
- mysql备份脚本-mysqldump
背景:全库备份 备份流程: 1.生成DB列表,将DB名字写入文件 2.定义备份函数,结果写入SQL文件 3.压缩文件,减少磁盘占用量 4.设置保留天数,定期删除n天之前的 5.通过for循环读取DB列 ...
- 《Java程序设计》实验3
20145318 <Java程序设计>实验3 实验内容 使用 git 上传代码 使用 git 相互更改代码 实现代码的重载 PSP 队友链接 http://www.cnblogs.com/ ...
- 内核启动时在挂载ubi文件系统时提示UBIFS error (ubi0:0 pid 1): ubifs_read_superblock: min. I/O unit mismatch
一.背景 1.1 笔者机器的内核错误信息如下: UBIFS error (ubi0:0 pid 1): ubifs_read_superblock: min. I/O unit mismatch: 2 ...
- 使用ubifs作为根文件系统的openwrt如何在进行sysupgrade时保存旧的配置
1.openwrt的默认方案(squashfs + jffs2) sysupgrade脚本直接调用default_do_upgrade更新设备树.内核.根文件系统,那么它是如何保存旧配置的呢?请看de ...
- RedHat7.4最小化安装yum源不可用问题解决
本次安装的RedHat7.4是安装在Oracle VM VirtualBox5.2.8虚拟机上面的,本文不对安装虚拟机步骤做详细说明. 工具准备: Oracle VM VirtualBox5.2.8 ...
- 使用cxf调用webservice
1.引入maven包 <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt ...
- ***使用jQuery去封装插件(组件化、模块化的思想),即扩展方法
如何使用jQuery去封装插件,区分扩展全局方法与扩展一个普通的jQuery实例对象的方法 1.给全局对象扩展方法:①$.方法 = function(参数可加可不加){} ②使用:$.方法(有参数的 ...