本文介绍了弹性搜索中的多个组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用ES中的3个字段进行聚合(group-by)。

I need to aggregate (group-by) using 3 fields in ES.

我可以在1个查询中执行此操作,还是需要使用facet + iterate对于每一列?

Can I do that in 1 query or that I need to use a facet + iterate for each column?

谢谢

推荐答案

你可以做通过两种方式:

You can do it by 2 ways :

1)在单个方面结果中使用多个字段:

1) using multiple fields in a single facet result :

单个字段facet的示例:

example for single fields facet :

curl -X GET "http://localhost:9200/sales/order/_search?pretty=true" -d '{
  "query": {
    "query_string": {
      "query": "shohi*",
      "fields": [
        "billing_name"
      ]
    }
  },
  "facets": {
    "facet_result": {
      "terms": {
        "fields": [
          "status"
        ],
        "order": "term",
        "size": 15
      }
    }
  }
}'

单个方面结果中的多个字段的示例:

example for multiple field in a single facet result :

curl -X GET "http://localhost:9200/sales/order/_search?pretty=true" -d '{
  "query": {
    "query_string": {
      "query": "shohi*",
      "fields": [
        "billing_name"
      ]
    }
  },
  "facets": {
    "facet_result": {
      "terms": {
        "fields": [
          "status",
          "customer_gender",
          "state"
        ],
        "order": "term",
        "size": 15
      }
    }
  }
}'

2)使用多个方面的结果集:

2) Use multiple facet result set :

curl -X GET "http://localhost:9200/sales/order/_search?pretty=true" -d '{
  "query": {
    "query_string": {
      "query": "*",
      "fields": [
        "increment_id"
      ]
    }
  },
  "facets": {
    "status_facets": {
      "terms": {
        "fields": [
          "status"
        ],
        "size": 50,
        "order": "term"
      }
    },
    "gender_facets": {
      "terms": {
        "fields": [
          "customer_gender"
        ]
      }
    },
    "state_facets": {
      "terms": {
        "fields": [
          "state"
        ],
        ,
        "order": "term"
      }
    }
  }
}'

参考链接:

这篇关于弹性搜索中的多个组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 01:20