内部オブジェクトを持つデータに集計したい。たとえば:ElasticSearch 1x - オブジェクト条件の集計
{
"_index": "product_index-en",
"_type": "elasticproductmodel",
"_id": "000001111",
"_score": 6.3316255,
"_source": {
"productId": "11111111111",
"productIdOnlyLetterAndDigit": "11111111111",
"productIdOnlyDigit": "11111111111",
"productNumber": "11111111111",
"name": "Glow Plug",
"nameOnlyLetterAndDigit": "glowplug",
"productImageLarge": "11111111111.jpg",
"itemGroupId": "11111",
"relatedProductIds": [],
"dataAreaCountries": [
"fra",
"pol",
"uk",
"sie",
"sve",
"atl",
"ita",
"hol",
"dk"
],
"oemItems": [
{
"manufactorName": "BERU",
"manufacType": "0"
},
{
"manufactorName": "LUCAS",
"manufacType": "0"
}
]
}
}
私は可能な集合体oemItems.manufactorName値である必要がありますが、oemItems.manufacTypeは「0」である場合にのみ。私はここで受け入れられたもの(Elastic Search Aggregate into buckets on conditions)のようないくつかの例を試しましたが、私はそれの周りに私の頭を包むように見えません。
まずmanufacTypeを実行してから、正しいタイプのヒット数を表示するように各タイプのmanufactorNameを作成してみてください。しかし、manufactorName用バケットが空である:
GET /product_index-en/_search
{
"size": 0,
"aggs": {
"baked_goods": {
"nested": {
"path": "oemItems"
},
"aggs": {
"test1": {
"terms": {
"field": "oemItems.manufacType",
"size": 500
},
"aggs": {
"test2": {
"terms": {
"field": "oemItems.manufactorName",
"size": 500
}
}
}
}
}
}
}
}
そして結果:
{
"took": 27,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 471214,
"max_score": 0,
"hits": []
},
"aggregations": {
"baked_goods": {
"doc_count": 677246,
"test1": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "0",
"doc_count": 436557,
"test2": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
},
{
"key": "1",
"doc_count": 240689,
"test2": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
]
}
}
}
}
私はまた、次のクエリでmanufacType 1持っているだけでoemItemsを見て、ネストされた用語のフィルタを追加しようとしました。ただし、oemItemsにmanufacType 1が含まれているオブジェクトを返します。つまり、製品内のoemItemsには1または0のmanufacTypeが含まれています。私はoemItems.manufacTypeがこれまで0
GET /product_index-en/_search
{
"query" : { "match_all" : {} },
"filter" : {
"nested" : {
"path" : "oemItems",
"filter" : {
"bool" : {
"must" : [
{
"term" : {"oemItems.manufacType" : "1"}
}
]
}
}
}
}
}
まず、マッピングで 'oemItems'が' nested'型であることを確認する必要があります。それは事実ですか? – Val
@Valいいえ、ネストされた型ではありません。私はそれを変更し、それが役立つかどうかを確認します。 –
@Valこれを入れ子にして、私の投稿に例を追加しました。 –