微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 nest c# 的 Elasticsearch 过滤器组

如何解决使用 nest c# 的 Elasticsearch 过滤器组

我正在使用弹性搜索获取按类别分组的产品并对结果执行聚合.... 如果我使用 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,你应该很好。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?