2017-09-04 1 views
3

Elasticsearch에서 많은 양의 데이터가 있습니다. 내 douments에는 여러 필드가있는 객체 목록을 포함하는 "레코드"라는 중첩 필드가 있습니다.중첩 된 내부 히트에 대한 탄성 검색 집계

레코드 목록에서 특정 개체를 쿼리 할 수 ​​있기를 원하기 때문에 내 쿼리에서 inner_hits 필드를 사용하지만 집계가 크기 0을 사용하므로 결과가 반환되지 않으므로 도움이되지 않습니다.

집계는 쿼리와 상관없이 레코드 내의 모든 개체에 대한 결과를 반환하므로 inner_hits에 대해서만 집계 작업을 수행하는 데 성공하지 못했습니다. (각 문서가 first_timestamp 및 last_timestamp 필드 및 기록 목록의 각 개체가 타임 스탬프 필드가)

curl -XPOST 'localhost:9200/_msearch?pretty' -H 'Content-Type: application/json' -d'  
{ 
    "index":[ 
     "my_index" 
    ], 
    "search_type":"count", 
    "ignore_unavailable":true 
} 
{ 
    "size":0, 
    "query":{ 
     "filtered":{ 
      "query":{ 
       "nested":{ 
        "path":"records", 
        "query":{ 
         "term":{ 
          "records.data.field1":"value1" 
         } 
        }, 
        "inner_hits":{} 
       } 
      }, 
      "filter":{ 
       "bool":{ 
        "must":[ 
        { 
         "range":{ 
          "first_timestamp":{ 
           "gte":1504548296273, 
           "lte":1504549196273, 
           "format":"epoch_millis" 
          } 
         } 
        } 
        ], 
       } 
      } 
     } 
    }, 
    "aggs":{ 
     "nested_2":{ 
      "nested":{ 
       "path":"records" 
      }, 
      "aggs":{ 
       "2":{ 
        "date_histogram":{ 
          "field":"records.timestamp", 
          "interval":"1s", 
          "min_doc_count":1, 
          "extended_bounds":{ 
           "min":1504548296273, 
           "max":1504549196273 
          } 
        } 
       } 
      } 
     } 
    } 
}' 

답변

3

귀하의 질의가 꽤 복잡하다 :

내가 사용하고있는 쿼리입니다. > 우리가 안타에 관심이없는 만 집계 - 0 :

  • 크기 : 나를 집계의 이름으로 모든 단계를 설명하자, 이제

    { 
        "size": 0, 
        "aggregations": { 
        "nested_A": { 
         "nested": { 
         "path": "records" 
         }, 
         "aggregations": { 
         "bool_aggregation_A": { 
          "filter": { 
          "bool": { 
           "must": [ 
           { 
            "term": { 
            "records.data.field1": "value1" 
            }  
           } 
           ] 
          } 
          }, 
          "aggregations": { 
          "reverse_aggregation": { 
           "reverse_nested": {}, 
           "aggregations": { 
           "bool_aggregation_B": { 
            "filter": { 
            "bool": { 
             "must": [ 
             { 
              "range": { 
              "first_timestamp": { 
               "gte": 1504548296273, 
               "lte": 1504549196273, 
               "format": "epoch_millis" 
              } 
              } 
             } 
             ] 
            } 
            }, 
            "aggregations": { 
            "nested_B": { 
             "nested": { 
             "path": "records" 
             }, 
             "aggregations": { 
             "my_histogram": { 
              "date_histogram": { 
              "field": "records.timestamp", 
              "interval": "1s", 
              "min_doc_count": 1, 
              "extended_bounds": { 
               "min": 1504548296273, 
               "max": 1504549196273 
              } 
              } 
             } 
             } 
            } 
            } 
           } 
           } 
          } 
          } 
         } 
         } 
        } 
        } 
    } 
    

    : 여기에 귀하의 요청 쿼리입니다, 짧게

  • nested_A
  • - 우리가 기록에 우리의 범위를 뛰어 있도록> data.field1 레코드 아래
  • bool_aggregation_A - data.field1으로> 필터 : 값 1
  • reverse_aggregation -> 이제, 범위 다시 timestamp 필드의 레코드에 (기록 아래에 위치)
  • -> 필터
  • nested_B 범위 first_timestamp 의해 ->first_timestamp 내포 문서에없는 우리
  • bool_aggregation_B 레코드로부터 스코프 필요
  • my_histogram -> finally, 집계 날짜 막대 그래프 timestamp 필드
+1

아름다운! 이것은 내가 의미했던 바로 그 것이다. – hanetz