问题描述
我正在使用弹性搜索来获取按类别分组的产品并对结果执行聚合.... 如果我使用 categoryid(numeric) 作为字段,它会给出结果,但是当我尝试给出类别名称时,它会给出 Unsuccessful(400)
请看打击代码片段
ISearchResponse<Products> results;
results = _client.Search<Products>(s => s
//.Size(int.MaxValue)
.Query(q => q
.Bool(b => b
.Should(
bs => bs.Prefix(p => p.cat_name,"heli"),bs => bs.Prefix(p => p.pr_name,"heli")
)
)
)
.Aggregations(a => a
.Terms("catname",t => t
.Field(f => f.categoryid)
.Size(int.MaxValue)
.Aggregations(agg => agg
.Max("maxprice",av => av.Field(f2 => f2.price))
.Average("avgprice",av => av.Field(f3 => f3.price))
.Max("maxweidht",av => av.Field(f2 => f2.weight))
.Average("avgweight",av => av.Field(f3 => f3.weight))
)
)
)
);
映射模型:
{
"product_catalog": {
"mappings": {
"properties": {
"@timestamp": {
"type": "date"
},"@version": {
"type": "text","fields": {
"keyword": {
"type": "keyword","ignore_above": 256
}
}
},"cat_name": {
"type": "text","categoryid": {
"type": "long"
},"createdon": {
"type": "date"
},"fulldescription": {
"type": "text","height": {
"type": "float"
},"length": {
"type": "float"
},"pr_name": {
"type": "text","price": {
"type": "long"
},"productid": {
"type": "long"
},"shortdescription": {
"type": "text","sku": {
"type": "text","updatedon": {
"type": "date"
},"weight": {
"type": "float"
},"width": {
"type": "float"
}
}
}
}
}
谁能指导如何使用类别名称进行分组。
解决方法
$("#AddGrid").kendoGrid({
dataSource: AddGriddataSource,selectable: "row",scrollable: false,columns: AddGridCells,change: numberInput,pageable: {
buttonCount: 3,messages: GridPageMsg
},height: '100%',editable: true
}).data("kendoGrid");
字段的类型为 $(document).on('click','.returnPlus',function (e) {
if (nowStatus != 0) {
return;
}
var ds2 = $("#AddGrid").data("kendoGrid").dataSource;
var row = $(this).closest("tr"),grid = $("#AddGrid").data("kendoGrid"),dataItem = grid.dataItem(row);
debugger;
ds2.fetch(function () {
dataItem.txtReturnNum = dataItem.txtReturnNum - (-1);
dataItem.txtPriceNum = dataItem.txtReturnNum * dataItem.txtPrice;
dataItem.txtPriceNum1 = mulFloat(dataItem.txtReturnNum,dataItem.txtPricetax);
})
$("#AddGrid").data("kendoGrid").refresh();
return;
});
$(document).on('click','.returnDel',function (e) {
if (nowStatus != 0) {
return;
}
var ds2 = $("#AddGrid").data("kendoGrid").dataSource;
var row = $(this).closest("tr"),dataItem = grid.dataItem(row);
debugger;
ds2.fetch(function () {
dataItem.txtReturnNum = dataItem.txtReturnNum - (1);
dataItem.txtPriceNum = dataItem.txtReturnNum * dataItem.txtPrice;
dataItem.txtPriceNum1 = mulFloat(dataItem.txtReturnNum,dataItem.txtPricetax);
})
$("#AddGrid").data("kendoGrid").refresh();
return;
});
,因此默认情况下您不能在聚合中使用它,因为 fielddata
is disabled 出于性能原因。
根据您的映射,我看到您也在为 catname
编制索引 text
,因此您可以使用此字段。
只需将术语聚合 keyword
的这一部分更改为
catname
,你应该很好。