2016-04-07 13 views
3

Gönderilen benzer soruları gördüm, ama elbette, hiçbiri yapmaya çalıştığım tam olarak değil. Bu hatayı alıyorum aşağıdaki I sorguyu çalıştırdığınızdaElasticsearch: Yuvalanmış bir dizi sorgulama

:

"reason": "[nested] failed to find nested object under path [contentGroup]"

Sorun contentGroup bir dizi değil bir nesne olduğu için contentGroup.name yok olduğunu düşünüyorum. Bunun gibi bir şey olması gerekir: contentGroup [0] .name ve contentGroup [1] .name Ancak bunu nasıl yapacağımı anlayamıyorum.

Yanlış olabilecek başka bir şey, birbirinin içine yerleştirilmiş iki öğem olduğudur, bunun doğru olup olmadığını bilmiyorum.

Herhangi bir yardım harika olurdu!

Benim haritalama:

{ 
"mappings": { 
    "articles": { 
     "properties": { 
      "contentGroups": { 
       "type": "nested", 
       "properties": { 
        "contentGroup": { 
         "type": "nested", 
         "properties": { 
          "id": { 
          "type": "string" 
          }, 
          "name": { 
           "type": "string" 
          } 
         } 
        } 
       } 
      } 
     } 
    } 
} 

Ne bir makalede girdi oluşturulan alır (dizi Not yaratılan):

"contentGroups": { 
"contentGroup": [ 
    { 
     "name": "Breaking", 
     "id": "104" 
    }, 
    { 
     "name": "News", 
     "id": "22" 
    } 
] 

Benim sorgusu:

{ 
"query": { 
    "bool": { 
     "must": [ 
      { "match": { "headline": "whatever" }}, 
      { 
       "nested": { 
        "path": "contentGroup", 
        "query": { 
         "bool": { 
          "must": [ 
           { "match": { "contentGroup.name": "Breaking" }} 
          ] 
         } 
        } 
       } 
      } 
     ] 
    } 
} 

cevap

3

Gitmelisiniz daha basit eşlemeyi kullanın:

{ 
    "mappings": { 
    "articles": { 
     "properties": { 
     "contentGroups": { 
      "properties": { 
      "id": { 
       "type": "string" 
      }, 
      "name": { 
       "type": "string" 
      } 
      } 
     } 
     } 
    } 
    } 
} 

Elasticsearch'teki her alan zaten birden fazla değeri desteklemektedir, bunu belirtmenize gerek yoktur.

+1

Bu benim için çalıştı! Böyle basit bir çözüm! Teşekkür ederiz! –