elasticsearch为什么这么慢?

时间:2016-06-21 13:21:03

标签: elasticsearch aggregate facet

对于没有facet的以下查询。花了18毫秒。 但是在加入facet之后它需要7408毫秒。

我有183M的记录。

Facets基于搜索查询提供聚合数据。对???
那么为什么facet花了这么多时间在40条记录上进行聚合呢?

没有方面的询问:花了18毫秒

{ 
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "country_raw": "united states"
              }
            },
            {
              "term": {
                "title_raw": "manager"
              }
            }
          ]
        }
      }
    }
  }
}

没有构面查询的响应:

{
    "took": 18,
    "timed_out": false,
    "_shards": {
        "total": 6,
        "successful": 6,
        "failed": 0
    },
    "hits": {
        "total": 40,
        "max_score": 1,
        "hits": [ 
        ....
        ]
    }
}

使用facet查询:获得7845毫秒秒

{
 "size": 0
 "facets": {
    "title_facet": {
      "terms": {
        "field": "title_raw",
        "size": 5
      }
    }
  },
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "country_raw": "united states"
              }
            },
            {
              "term": {
                "title_raw": "manager"
              }
            }
          ]
        }
      }
    }
  }
}

分面查询响应

{
    "took": 7408,
    "timed_out": false,
    "_shards": {
        "total": 6,
        "successful": 6,
        "failed": 0
    },
    "hits": {
        "total": 40,
        "max_score": 0,
        "hits": [ ]
    },
    "facets": {
        "title_facet": {
            "_type": "terms",
            "missing": 0,
            "total": 40,
            "other": 0,
            "terms": [
                {
                    "term": "manager",
                    "count": 40
                }
            ]
        }
    }
}

1 个答案:

答案 0 :(得分:0)

你试过" aggs"而不是" facet" (我记得那个方面已被贬低)

https://www.elastic.co/guide/en/elasticsearch/reference/1.4/search-aggregations-bucket-terms-aggregation.html

{
    "query" : {
        "filtered" : {
            "filter" : {
                "bool" : {
                    "must" : [{
                            "term" : {
                                "country_raw" : "united states"
                            }
                        }, {
                            "term" : {
                                "title_raw" : "manager"
                            }
                        }
                    ]
                }
            }
        }
    },
    "aggs" : {
        "title_facet" : {
            "terms" : {
                "field" : "title_raw",
                "size" : 5
            }
        }
    },
    "sort" : {
        "_score" : "desc"
    }
}