elasticsearch - 如何计算 Elasticsearch 中嵌套字段中的对象数?

标签 elasticsearch

如何计算 Elasticsearch 中嵌套字段中的对象数? 示例映射:

"base_keywords": {
  "type": "nested",
  "properties": {
    "base_key": {
      "type": "text"
    },
    "category": {
      "type": "text"
    },
    "created_at": {
      "type": "date"
    },
    "date": {
      "type": "date"
    },
    "rank": {
      "type": "integer"
    }
  }
}

我想计算嵌套字段“base_keywords”中的对象数。

最佳答案

您需要使用内联脚本来执行此操作。这对我有用:(使用 ES 6.x):

GET your-indices/_search
{

  "aggs": {
    "whatever": {
      "sum": {
        "script": {
          "inline": "params._source.base_keywords.size()"
        }
      }
    }
  }
}

关于elasticsearch - 如何计算 Elasticsearch 中嵌套字段中的对象数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48881017/

相关文章:

ElasticSearch - 短语建议器

python - 如何在python中使用ElasticSearch-dsl自定义同义词 token 过滤器?

elasticsearch - ES 创建数据传输

elasticsearch - 使Elasticsearch同义词起作用吗?

elasticsearch - 模糊查询不返回记录

elasticsearch - 使用X-pack启动Elastic搜索时引发异常

elasticsearch - Elasticsearch字段数据与字段映射

elasticsearch - 遇到可重试的错误。将使用指数退避重试 { :code=>400, :url= >"https://example.us-east-1.es.amazonaws.com:443/_bulk"}

java - 使用 JEST 写入 Elasticsearch 7.3 - 无效的 POST 方法

c# - 使用自定义字段进行 Elasticsearch 的 Serilog 配置