2014-09-20 13 views
5

Sto tentando di utilizzare un filtro di query nidificato all'interno di un'aggregazione di filtri annidata. Quando lo faccio, l'aggregazione restituisce senza elementi. Se cambio la query in un semplice vecchio filtro match_all, restituisco gli elementi nel bucket.La query nidificata in annidata, l'aggregazione dei filtri non riesce

Ecco una versione semplificata della mappatura sto lavorando con:

"player": { 
    "properties": { 
    "rating": { 
     "type": "float" 
    }, 
    "playerYears": { 
     "type": "nested", 
     "properties": { 
     "schoolsOfInterest": { 
      "type": "nested", 
      "properties": { 
      "name": { 
       "type": "string", 
       "index": "not_analyzed" 
      } 
      } 
     } 
     } 
    } 
    } 
} 

Questa query, con un filtro match_all sull'aggregazione:

GET /players/_search 
{ 
    "size": 0, 
    "aggs": { 
    "rating": { 
     "nested": { 
     "path": "playerYears" 
     }, 
     "aggs": { 
     "rating-filtered": { 
      "filter": { 
       "match_all": {} 
      }, 
      "aggs": { 
      "rating": { 
       "histogram": { 
       "field": "playerYears.rating", 
       "interval": 1 
       } 
      } 
      } 
     } 
     } 
    } 
    }, 
    "query": { 
    "filtered": { 
     "filter": { 
     "match_all": {} 
     } 
    } 
    } 
} 

restituisce il seguente:

{ 
    "took": 16, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 167316, 
     "max_score": 0, 
     "hits": [] 
    }, 
    "aggregations": { 
     "rating": { 
     "doc_count": 363550, 
     "rating-filtered": { 
      "doc_count": 363550, 
      "rating": { 
       "buckets": [ 
        { 
        "key_as_string": "-1", 
        "key": -1, 
        "doc_count": 20978 
        }, 
        { 
        "key_as_string": "0", 
        "key": 0, 
        "doc_count": 312374 
        }, 
        { 
        "key_as_string": "1", 
        "key": 1, 
        "doc_count": 1162 
        }, 
        { 
        "key_as_string": "2", 
        "key": 2, 
        "doc_count": 12104 
        }, 
        { 
        "key_as_string": "3", 
        "key": 3, 
        "doc_count": 9558 
        }, 
        { 
        "key_as_string": "4", 
        "key": 4, 
        "doc_count": 5549 
        }, 
        { 
        "key_as_string": "5", 
        "key": 5, 
        "doc_count": 1825 
        } 
       ] 
      } 
     } 
     } 
    } 
} 

Ma questa query, che ha un filtro nidificato nell'aggregazione, restituisce un bucket vuoto:

GET /players/_search 
{ 
    "size": 0, 
    "aggs": { 
    "rating": { 
     "nested": { 
     "path": "playerYears" 
     }, 
     "aggs": { 
     "rating-filtered": { 
      "filter": { 
       "nested": { 
       "query": { 
        "match_all": {} 
       }, 
       "path": "playerYears.schoolsOfInterest" 
      } 
      }, 
      "aggs": { 
      "rating": { 
       "histogram": { 
       "field": "playerYears.rating", 
       "interval": 1 
       } 
      } 
      } 
     } 
     } 
    } 
    }, 
    "query": { 
    "filtered": { 
     "filter": { 
     "match_all": {} 
     } 
    } 
    } 
} 

il secchio vuoto:

{ 
    "took": 8, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 167316, 
     "max_score": 0, 
     "hits": [] 
    }, 
    "aggregations": { 
     "rating": { 
     "doc_count": 363550, 
     "rating-filtered": { 
      "doc_count": 0, 
      "rating": { 
       "buckets": [] 
      } 
     } 
     } 
    } 
} 

E 'possibile utilizzare filtri nidificati all'interno di annidate, aggregazioni filtrati? C'è un bug noto in elasticsearch a riguardo? Il filtro annidato funziona bene nel contesto della query della ricerca e funziona correttamente se non utilizzo un'aggregazione annidata.

+0

puoi provare la seguente parte nell'aggregazione di filtri nidificati? "aggs": { "voto-filtrato": { "filtro": { "annidati": { "filtro": { "match_all": {}} , "percorso": "playerYears.schoolsOfInterest " } }, –

+0

Era l'unica modifica da una query a un filtro? Se è così, l'ho provato e non ho preso un dado. ancora nessun risultato :( – Bennidhamma

+0

potete fornire alcuni documenti di esempio? –

risposta

11

Sulla base delle informazioni fornite e di alcune ipotesi, vorrei fornire due suggerimenti. Spero che aiuti a risolvere il tuo problema.

Caso 1: usando inverso aggregazione nidificato:

{ 
    "size": 0, 
    "query": { 
    "match_all": {} 
    }, 
    "aggs": { 
    "rating": { 
     "nested": { 
     "path": "playerYears.schoolsOfInterest" 
     }, 
     "aggs": { 
     "rating-filtered": { 
      "filter": { 
      "match_all": {} 
      }, 
      "aggs": { 
      "rating_nested": { 
       "reverse_nested": {}, 
       "aggs": { 
       "rating": { 
        "histogram": { 
        "field": "rating", 
        "interval": 1 
        } 
       } 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
} 

Caso 2: modifiche alla aggregazione filtrato:

{ 
    "size": 0, 
    "aggs": { 
    "rating-filtered": { 
     "filter": { 
     "nested": { 
      "query": { 
      "match_all": {} 
      }, 
      "path": "playerYears.schoolsOfInterest" 
     } 
     }, 
     "aggs": { 
     "rating": { 
      "histogram": { 
      "field": "playerYears.rating", 
      "interval": 1 
      } 
     } 
     } 
    } 
    }, 
    "query": { 
    "filtered": { 
     "filter": { 
     "match_all": {} 
     } 
    } 
    } 
} 

vorrei suggerire di utilizzare il caso 1 e verificare la tua richiesta risultati.

+0

Penso che funzionerà !! – Bennidhamma

Problemi correlati