2017-03-07 9 views
0

カーディナリティー集約を使用して異なる値のカウントを取得しようとしています。ここフィルター集約内の基数集約

はその後

{ 
    "size": 100, 
    "_source":["awardeeName"], 
    "query": { 
     "match_phrase":{"awardeeName" :"The President and Fellows of Harvard College" } 
    }, 
    "aggs":{ 
     "awardeeName": { 
      "filter" : { "query": { "match_phrase":{"awardeeName" :"The President and Fellows of Harvard College" }}}, 
      "aggs": { 
       "distinct":{"cardinality":{ "field": "awardeeName"}} 
      } 
     } 

    }    
} 

いくつかのテキストのmatch_phraseを使用して、クエリ、同じ試合のフレーズと集計し、その結果カーディナリティ、 を呼び出し、カウント数と集計fitlerの試合を打つ私のクエリですが、カーディナリティは意外に別の番号を示していフィルタおよび総ヒット数より大きく、ここで結果

{ 
    "took": 37, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 3, 
     "max_score": 13.516766, 
     "hits": [ 
      { 
       "_index": "development", 
       "_type": "document", 
       "_id": "140a3f5b-e876-4542-b16d-56c3c5ae0e58", 
       "_score": 13.516766, 
       "_source": { 
        "awardeeName": "The President and Fellows of Harvard College" 
       } 
      }, 
      { 
       "_index": "development", 
       "_type": "document", 
       "_id": "5c668b06-c612-4349-8735-2a79ee2bb55e", 
       "_score": 12.913888, 
       "_source": { 
        "awardeeName": "The President and Fellows of Harvard College" 
       } 
      }, 
      { 
       "_index": "development", 
       "_type": "document", 
       "_id": "a9560519-1b2a-4e64-b85f-4645a41d5810", 
       "_score": 12.913888, 
       "_source": { 
        "awardeeName": "The President and Fellows of Harvard College" 
       } 
      } 
     ] 
    }, 
    "aggregations": { 
     "awardeeName": { 
      "doc_count": 3, 
      "distinct": { 
       "value": 7 
      } 
     } 
    } 
} 

である私は、基数がフィルタの結果に適用することを期待するが、この場合にはカーディナリティは7を示し、なぜそれが7を示していますか?別の値のカウントは、ヒット数の合計をどのように超えることができますか?

答えて

1

awardeeNameフィールドのcardinalityアグリゲーションは、一致するすべてのドキュメントのフィールドに存在する別個のトークンの数をカウントしています。

あなたのケースでは、一致する3つのドキュメントでは、awardeeNameフィールドに正確に同じトークンを持つThe President and Fellows of Harvard Collegeという正確な値が含まれているため、7の結果が表示されます。あなたはおそらく達成したい何

は、単一のトークンとしてThe President and Fellows of Harvard Collegeをカウントし、そのためにあなたが(代わりにtext 1の)keyword fieldを必要とし、あなたのcardinality集計でそのフィールドを使用することです。

+0

キーワードは、値 'college'の照合クエリの場合は0レコードを返します。データ型テキストを保持するmatchとmatch_phraseの両方で検索したいのですが、別のフィールド値を数える方法はありますか? – user884424

+0

私はこのプロパティを2つの異なるフィールドとしてマップすることができます。テキストアナラ​​イザによる全文検索とキーワードアナライザによる別個のカウントなどです。 – user884424

+0

これは間違いなく、マルチフィールド、つまり全文検索用のフィールドとキーワードアナライザ付きの別のサブフィールドが必要になる場合があります。 – Val