2017-10-04 11 views
0

J'ai la requête ci-dessous - générée par grafana qui renvoie des valeurs nulles lorsque je cours sur un index où le type "buckets" est imbriqué.Agrégation Elasticsearch La requête sur le type imbriqué renvoie des valeurs nulles mais renvoie des nombres par rapport au type non imbriqué

Mais la même requête renvoie des nombres non nuls quand je courir contre le même indice que j'ai « seaux » champ comme un type non imbriqué

Ci-dessous la requête:

{ 
"size": 0, 
"query": { 
    "bool": { 
     "filter": [{ 
       "range": { 
        "timestamp": { 
         "from": "1504818600000", 
         "to": "1504818780000", 
         "include_lower": true, 
         "include_upper": true, 
         "format": "epoch_millis", 
         "boost": 1.0 
        } 
       } 
      }, 
      { 
       "query_string": { 
        "query": "app_name:ssss AND buckets.name:dddr", 
        "fields": [], 
        "use_dis_max": true, 
        "tie_breaker": 0.0, 
        "default_operator": "or", 
        "auto_generate_phrase_queries": false, 
        "max_determinized_states": 10000, 
        "enable_position_increments": true, 
        "fuzziness": "AUTO", 
        "fuzzy_prefix_length": 0, 
        "fuzzy_max_expansions": 50, 
        "phrase_slop": 0, 
        "analyze_wildcard": true, 
        "escape": false, 
        "split_on_whitespace": true, 
        "boost": 1.0 
       } 
      } 
     ], 
     "disable_coord": false, 
     "adjust_pure_negative": true, 
     "boost": 1.0 
    } 
}, 
"aggregations": { 
    "2": { 
     "date_histogram": { 
      "field": "timestamp", 
      "format": "epoch_millis", 
      "interval": "1m", 
      "offset": 0, 
      "order": { 
       "_key": "asc" 
      }, 
      "keyed": false, 
      "min_doc_count": 0, 
      "extended_bounds": { 
       "min": "1504818600000", 
       "max": "1504818780000" 
      } 
     }, 
     "aggregations": { 
      "1": { 
       "avg": { 
        "field": "buckets.basicStats.memUsed" 
       } 
      } 
     } 
    } 
} 
} 

Run contre un type non imbriqué:

{ 
"took" : 4, 
"timed_out" : false, 
"_shards" : { 
"total" : 5, 
"successful" : 5, 
"skipped" : 0, 
"failed" : 0 
}, 
"hits" : { 
"total" : 3, 
"max_score" : 0.0, 
"hits" : [ ] 
}, 
"aggregations" : { 
"2" : { 
    "buckets" : [ 
    { 
     "key_as_string" : "1504818600000", 
     "key" : 1504818600000, 
     "doc_count" : 1, 
     "1" : { 
     "value" : 1.03766064E8 
     } 
    }, 
    { 
     "key_as_string" : "1504818660000", 
     "key" : 1504818660000, 
     "doc_count" : 1, 
     "1" : { 
     "value" : 1.0376628E8 
     } 
    }, 
    { 
     "key_as_string" : "1504818720000", 
     "key" : 1504818720000, 
     "doc_count" : 1, 
     "1" : { 
     "value" : 1.0376628E8 
     } 
    }, 
    { 
     "key_as_string" : "1504818780000", 
     "key" : 1504818780000, 
     "doc_count" : 0, 
     "1" : { 
     "value" : null 
     } 
    } 
    ] 
} 
} 
} 

Mais lorsqu'il est exécuté sur un type imbriqué:

"buckets" : [ 
    { 
     "key_as_string" : "1504818600000", 
     "key" : 1504818600000, 
     "doc_count" : 0, 
     "1" : { 
     "value" : null 
     } 
    }, 
    { 
     "key_as_string" : "1504818660000", 
     "key" : 1504818660000, 
     "doc_count" : 0, 
     "1" : { 
     "value" : null 
     } 
    }, 
    { 
     "key_as_string" : "1504818720000", 
     "key" : 1504818720000, 
     "doc_count" : 0, 
     "1" : { 
     "value" : null 
     } 
    }, 
    { 
     "key_as_string" : "1504818780000", 
     "key" : 1504818780000, 
     "doc_count" : 0, 
     "1" : { 
     "value" : null 
     } 
    } 
    ] 

Existe-t-il un moyen pour moi de modifier la requête à travailler pour un type imbriqué?

Ci-dessous la cartographie

{ 
"buckets": { 
    "mappings": { 
     "buckets": { 
      "properties": { 
       "app_name": { 
        "type": "text", 
        "fields": { 
         "keyword": { 
          "type": "keyword", 
          "ignore_above": 256 
         } 
        } 
       }, 
       "buckets": { 
        "type": "nested", 
        "properties": { 
         "authType": { 
          "type": "text", 
          "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
          } 
         }, 
         "autoCompactionSettings": { 
          "type": "boolean" 
         }, 
         "basicStats": { 
          "properties": { 
           "dataUsed": { 
            "type": "long" 
           }, 
           "diskFetches": { 
            "type": "long" 
           }, 
           "diskUsed": { 
            "type": "long" 
           }, 
           "itemCount": { 
            "type": "long" 
           }, 
           "memUsed": { 
            "type": "long" 
           }, 
           "opsPerSec": { 
            "type": "long" 
           }, 
           "quotaPercentUsed": { 
            "type": "float" 
           } 
          } 
         }, 
         "bucketCapabilities": { 
          "type": "text", 
          "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
          } 
         }, 
         "bucketCapabilitiesVer": { 
          "type": "text", 
          "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
          } 
         }, 
         "bucketType": { 
          "type": "text", 
          "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
          } 
         }, 
         "controllers": { 
          "properties": { 
           "compactAll": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "compactDB": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "flush": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "purgeDeletes": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "startRecovery": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           } 
          } 
         }, 
         "ddocs": { 
          "properties": { 
           "uri": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           } 
          } 
         }, 
         "evictionPolicy": { 
          "type": "text", 
          "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
          } 
         }, 
         "localRandomKeyUri": { 
          "type": "text", 
          "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
          } 
         }, 
         "name": { 
          "type": "text", 
          "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
          } 
         }, 
         "nodeLocator": { 
          "type": "text", 
          "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
          } 
         }, 
         "nodes": { 
          "type": "nested", 
          "properties": { 
           "clusterCompatibility": { 
            "type": "long" 
           }, 
           "clusterMembership": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "couchApiBase": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "couchApiBaseHTTPS": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "hostname": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "interestingStats": { 
            "properties": { 
             "cmd_get": { 
              "type": "long" 
             }, 
             "couch_docs_actual_disk_size": { 
              "type": "long" 
             }, 
             "couch_docs_data_size": { 
              "type": "long" 
             }, 
             "couch_spatial_data_size": { 
              "type": "long" 
             }, 
             "couch_spatial_disk_size": { 
              "type": "long" 
             }, 
             "couch_views_actual_disk_size": { 
              "type": "long" 
             }, 
             "couch_views_data_size": { 
              "type": "long" 
             }, 
             "curr_items": { 
              "type": "long" 
             }, 
             "curr_items_tot": { 
              "type": "long" 
             }, 
             "ep_bg_fetched": { 
              "type": "long" 
             }, 
             "get_hits": { 
              "type": "long" 
             }, 
             "mem_used": { 
              "type": "long" 
             }, 
             "ops": { 
              "type": "long" 
             }, 
             "vb_replica_curr_items": { 
              "type": "long" 
             } 
            } 
           }, 
           "mcdMemoryAllocated": { 
            "type": "long" 
           }, 
           "mcdMemoryReserved": { 
            "type": "long" 
           }, 
           "memoryFree": { 
            "type": "long" 
           }, 
           "memoryTotal": { 
            "type": "long" 
           }, 
           "os": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "otpNode": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "ports": { 
            "properties": { 
             "direct": { 
              "type": "long" 
             }, 
             "httpsCAPI": { 
              "type": "long" 
             }, 
             "httpsMgmt": { 
              "type": "long" 
             }, 
             "proxy": { 
              "type": "long" 
             }, 
             "sslProxy": { 
              "type": "long" 
             } 
            } 
           }, 
           "recoveryType": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "replication": { 
            "type": "long" 
           }, 
           "services": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "status": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "systemStats": { 
            "properties": { 
             "cpu_utilization_rate": { 
              "type": "float" 
             }, 
             "mem_free": { 
              "type": "long" 
             }, 
             "mem_total": { 
              "type": "long" 
             }, 
             "swap_total": { 
              "type": "long" 
             }, 
             "swap_used": { 
              "type": "long" 
             } 
            } 
           }, 
           "thisNode": { 
            "type": "boolean" 
           }, 
           "uptime": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "version": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           } 
          } 
         }, 
         "proxyPort": { 
          "type": "long" 
         }, 
         "quota": { 
          "properties": { 
           "ram": { 
            "type": "long" 
           }, 
           "rawRAM": { 
            "type": "long" 
           } 
          } 
         }, 
         "replicaIndex": { 
          "type": "boolean" 
         }, 
         "replicaNumber": { 
          "type": "long" 
         }, 
         "saslPassword": { 
          "type": "text", 
          "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
          } 
         }, 
         "stats": { 
          "properties": { 
           "directoryURI": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "nodeStatsListURI": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "uri": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           } 
          } 
         }, 
         "streamingUri": { 
          "type": "text", 
          "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
          } 
         }, 
         "threadsNumber": { 
          "type": "long" 
         }, 
         "timeSynchronization": { 
          "type": "text", 
          "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
          } 
         }, 
         "uri": { 
          "type": "text", 
          "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
          } 
         }, 
         "uuid": { 
          "type": "text", 
          "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
          } 
         }, 
         "vBucketServerMap": { 
          "properties": { 
           "hashAlgorithm": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           }, 
           "numReplicas": { 
            "type": "long" 
           }, 
           "serverList": { 
            "type": "text", 
            "fields": { 
             "keyword": { 
              "type": "keyword", 
              "ignore_above": 256 
             } 
            } 
           } 
          } 
         } 
        } 
       }, 
       "timestamp": { 
        "type": "date" 
       } 
      } 
     } 
    } 
} 
} 

Et un échantillon doc

"hits": [{ 
     "_index": "buckets", 
     "_type": "buckets", 
     "_id": "59b1b8c427f20beff758a6ac", 
     "_score": 2.361674, 
     "_source": { 
      "app_name": "sssss", 
      "buckets": [{ 
       "authType": "sasl", 
       "autoCompactionSettings": false, 
       "basicStats": { 
        "dataUsed": 123467470, 
        "diskFetches": 0, 
        "diskUsed": 153858414, 
        "itemCount": 21, 
        "memUsed": 87807640, 
        "opsPerSec": 0, 
        "quotaPercentUsed": 2.725907911856969 
       }, 
       "bucketCapabilities": ["cbhello", "touch", "couchapi", "cccp", "xdcrCheckpointing", "nodesExt", "dcp"], 
       "bucketCapabilitiesVer": "", 
       "bucketType": "membase", 
       "controllers": { 
        "compactAll": "/pools/default/buckets/config/controller/compactBucket", 
        "compactDB": "/pools/default/buckets/default/controller/compactDatabases", 
        "purgeDeletes": "/pools/default/buckets/config/controller/unsafePurgeBucket", 
        "startRecovery": "/pools/default/buckets/config/controller/startRecovery" 
       }, 
       "ddocs": { 
        "uri": "/pools/default/buckets/config/ddocs" 
       }, 
       "evictionPolicy": "valueOnly", 
       "localRandomKeyUri": "/pools/default/buckets/config/localRandomKey", 
       "name": "config", 
       "nodeLocator": "vbucket", 
       "nodes": [{ 
        "clusterCompatibility": 262149, 
        "clusterMembership": "active", 
        "couchApiBase": "http://lpdcbc01c.phx.aexp.com:8092/config%2B2fb1ce31a0421a3440047ad2a9e99bab", 
        "couchApiBaseHTTPS": "https://lpdcbc01c.phx.aexp.com:18092/config%2B2fb1ce31a0421a3440047ad2a9e99bab", 
        "hostname": "lpdcbc01c.phx.aexp.com:8091", 
        "interestingStats": { 
         "cmd_get": 0, 
         "couch_docs_actual_disk_size": 849296160, 
         "couch_docs_data_size": 727180093, 
         "couch_spatial_data_size": 0, 
         "couch_spatial_disk_size": 0, 
         "couch_views_actual_disk_size": 7610, 
         "couch_views_data_size": 7610, 
         "curr_items": 2022, 
         "curr_items_tot": 4069, 
         "ep_bg_fetched": 0, 
         "get_hits": 0, 
         "mem_used": 134052320, 
         "ops": 0, 
         "vb_replica_curr_items": 2047 
        }, 
        "mcdMemoryAllocated": 6347, 
        "mcdMemoryReserved": 6347, 
        "memoryFree": 5827776512, 
        "memoryTotal": 8319832064, 
        "os": "x86_64-unknown-linux-gnu", 
        "otpNode": "[email protected]", 
        "ports": { 
         "direct": 11210, 
         "httpsCAPI": 18092, 
         "httpsMgmt": 18091, 
         "proxy": 11211, 
         "sslProxy": 11214 
        }, 
        "recoveryType": "none", 
        "replication": 1, 
        "services": ["index", "kv", "n1ql"], 
        "status": "healthy", 
        "systemStats": { 
         "cpu_utilization_rate": 9.004739336492891, 
         "mem_free": 5827776512, 
         "mem_total": 8319832064, 
         "swap_total": 4294963200, 
         "swap_used": 0 
        }, 
        "uptime": "685303", 
        "version": "4.5.1-2844-enterprise" 
       }, { 
+0

Partagez votre mappage d'index et un exemple d'index. –

+0

J'ai ajouté le document de mappage et d'index dans le message d'origine. Merci! – user2405589

Répondre

0

Vous devez utiliser emboîtées agrégations lorsque vous faites agrégations contre les types imbriqués. Link

Remplacez votre agrégation par la ci-dessous et voyez si cela fonctionne pour vous.

"aggregations": { 
    "nested": { 
     "nested": { 
     "path": "buckets" 
     }, 
     "aggs": { 
     "1": { 
      "avg": { 
      "field": "buckets.basicStats.memUsed" 
      } 
     } 
     } 
    } 
    } 
+0

Ainsi, les agrégations régulières ne fonctionneront-elles pas sur les types imbriqués? – user2405589

+0

J'ai mis à jour ma réponse. –