2016-11-16 6 views
0

によって集約だから私はここでの問題を持っている...次項ジオ距離

私はそういずれかからソートElasticsearch集約を使用していElasticsearch

=> #<Chewy::SnippetPagesIndex::Query:0x007f911c6b1610 
@_collection=nil, 
@_fully_qualified_named_aggs={"chewy::snippetpagesindex"=>{"chewy::snippetpagesindex::snippetpage"=>{}}}, 
@_indexes=[Chewy::SnippetPagesIndex], 
@_named_aggs={}, 
@_request=nil, 
@_response=nil, 
@_results=nil, 
@_types=[], 
@criteria= 
    #<Chewy::Query::Criteria:0x007f911c6b1458 
    @aggregations= 
    {:group_by=>{:terms=>{:field=>"seo_area.suburb.id", :order=>{:_count=>"asc"}}, :aggs=>{:by_top_hit=>{:top_hits=>{:size=>10}}}}}, 
    @facets={}, 
    @fields=[], 
    @filters= 
    [{:geo_distance=>{:distance=>"100km", "seo_area.suburb.coordinates"=>"-27.9836052, 153.3977354"}}, 
    {:bool=> 
     {:must_not=>[{:terms=>{:id=>[1]}}, {:terms=>{"seo_area.suburb.id"=>[5559]}}], 
     :must=>[{:term=>{:path_category=>"garden-services"}}, {:term=>{:status=>"active"}}, {:exists=>{:field=>"path_area"}}], 
     :should=>[]}}], 
    @options= 
    {:query_mode=>:must, 
    :filter_mode=>:and, 
    :post_filter_mode=>:and, 
    :preload=> 
     {:scope=> 
     #<Proc:[email protected]/Users/serviceseeking/Work/serviceseeking/engines/seo/app/concepts/seo/snippet_page/twins/search.rb:45 (lambda)>}, 
    :loaded_objects=>true}, 
    @post_filters=[], 
    @queries=[], 
    @request_options={}, 
    @scores=[], 
    @script_fields={}, 
    @search_options={}, 
    @sort=[{:_geo_distance=>{"seo_area.suburb.coordinates"=>"-27.9836052, 153.3977354", :order=>"asc", :unit=>"km"}}], 
    @suggest={}, 
    @types=[]>, 
@options={}> 

との通信にchewyルビーの宝石を使用していますクエリ/検索フェーズは集約にアクセスすると消えてしまいます。

私は何を渡してきたことは私もこのエラーを取得してい

 aggs: { 
     by_seo_area_suburb_id: { 
      terms: { 
      field: "seo_area.suburb.id", 
      size: 10, 
      order: { by_distance: "desc" } 
      }, 
      aggs: { 
      by_top_hit: { 
       top_hits: { size: 10 } 
      }, 
      by_distance: { 
       geo_distance: { 
       field: "seo_area.suburb.coordinates", 
       origin: "52.3760, 4.894", 
       ranges: [ 
        { from: 0, to: 1 }, 
        { from: 1, to: 2 } 
       ] 
       } 
      } 
      } 
     } 
     } 

...これで...

[500] {"error":{"root_cause":[{"type":"aggregation_execution_exception","reason":"Invalid terms aggregation order path [by_distance]. Terms buckets can only be sorted on a sub-aggregator path that is built out of zero or more single-bucket aggregations within the path and a final single-bucket or a metrics aggregation at the path end."}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"snippet_pages","node":"srrlBssmSEGsqpZnPnOJmA","reason":{"type":"aggregation_execution_exception","reason":"Invalid terms aggregation order path [by_distance]. Terms buckets can only be sorted on a sub-aggregator path that is built out of zero or more single-bucket aggregations within the path and a final single-bucket or a metrics aggregation at the path end."}}]},"status":500} 

は単に...

規約を語りますバケットは、パス内の0個以上の単一バケット集約から構築されたサブアグリゲータパスと、パス終了時の最終シングルバケットまたはメトリック集約でのみソートできます。

答えて

0

あなたはこのようにバケツを持っていますので、上の

1-2

2-3

4-5

とを。これらは、自然順序を持つ単一値のバケットではありません。例外があなたに言っていることはそうです。だから、あなたはそれを一つの値に溶かすことが必要です。

ご注文いただいても可能です。どうしてですか? 1と2の間の距離のすべてが比較のために同じ値を持ち、それらの順序は未定義です。 0-1と1-2などを知ることができるだけの場合は、集約順序を変更してください。まず距離を取って、用語の部分集合を作成します。

{ name: "peter", location: [0,0] } 
{ name: "peter", location: [100,0] } 

明らか両方ピーターズは、用語の凝集の一つに溶けます:

すべてがすべてで、私は、あなたは、次の2つの文書を考えるため、集計はあなたが望むものではないされたユースケースを持っていると思います。しかし、彼らは2つの異なる場所を持っているので、距離は(ほとんど)常に異なるでしょう。だから、どのようにペットの距離を距離で注文できますか?フィールドを集計するとすぐに、他のフィールドはすべてそれから切り離され、他のフィールドは使用できません。

So.このようなことが必要な場合は、通常の検索を行う必要があります。距離を使って検索を並べ替える方法についてはこちらをご覧ください。

https://www.elastic.co/guide/en/elasticsearch/guide/current/sorting-by-distance.html