2015-03-30 20 views
16

İç içe geçmiş bir alan içeren belgemde arama yapmaya çalışıyorum. Böyle iç içe eşleme oluşturuldu:Elasticsearch: iç içe geçmiş nesnenin altındaki yolun iç içe türünde olmadığı

{ 
    "message": { 
    "properties": { 
     "messages": { 
     "type": "nested", 
     "properties": { 
      "message_id": { "type": "string" }, 
      "message_text": { "type": "string" }, 
      "message_nick": { "type": "string" } 
     } 
     } 
    } 
    } 
} 

Arama şöyle görünür: Henüz

curl -XGET 'localhost:9200/thread_and_messages/thread/_search' \ 
    -d '{"query": {"bool": {"must": [{"match": {"thread_name": "Banana"}}, {"nested": {"path": "messages", "query": {"bool": {"must": [{"match": {"messages.message_text": "Banana"}}]}}}]}}}}' 

Bu hata mesajı alıyorum:

QueryParsingException[[thread_and_messages] [nested] nested object under path [messages] is not of nested type] 

DÜZENLEMEYİ

Bu hatayı hala alıyorum.

{ 
    "_id": { 
    "path": "3", 
    "thread_id": "3", 
    "thread_name": "Banana", 
    "created": "Wed Mar 25 2015", 
    "first_nick": "AdminTech", 
    "messages": [ 
     { 
     "message_id": "9", 
     "message_text": "Banana", 
     "message_nick": "AdminTech" 
     } 
    ] 
    } 
} 

şöyle endeksi oluşturma:

CreateIndexRequestBuilder indexRequest = client.admin().indices().prepareCreate(INDEX).addMapping("message", mapping); 

Elimden yanlış belgeyi indeksliyorum düşünüyorum yüzden bu ı oluşturmaya çalışıyorum belgedir Java üzerinden yapıyorum.

cevap

16

TLDR: senin iç içe türü "type": "nested", koyun.

biz normal bir türü var ki, ve içinde yuvalanmış başka türü:

{ 
    "some_index": { 
     "mappings": { 
     "normal_type": { 
      "properties": { 
       "nested_type": { 
        "type": "nested", 
        "properties": { 
        "address": { 
         "type": "string" 
        }, 
        "country": { 
         "type": "string" 
        } 
        } 
       }, 
       "first_name": { 
        "type": "string" 
       }, 
       "last_name": { 
        "type": "string" 
       } 
      } 
     } 
     } 
    } 
} 

"type": "nested", çizgi böyle, "path":nested_type atanan hangi işe iç içe sorgular için gereklidir:

GET /some_index/normal_type/_search 
{ 
    "query": { 
    "nested": { 
     "query": { 
     "bool": {} 
     }, 
     "path": "nested_type" 
    } 
    } 
} 

"type": "nested", hattı yalnızca daha yeni Elasticsearch sürümlerinde (1.1.1'den beri) gerekli görünmektedir.

1

Sorgu DSL'sindeki sözdizimi hatası. query->bool->must

{ 
    "query": { 
     "bool": { 
       "must": [ 

      }// Should be ] 
     } 
    } 
} 

Doğru sürüm sorgusu engellemelidir için yanlış yaklaşıyorlar:

curl -XGET 'localhost:9200/thread_and_messages/thread/_search' -d '{ 
    "query": { 
     "bool": { 
     "must": [ 
      { 
       "match": { 
        "thread_name": "Banana" 
       } 
      }, 
      { 
       "nested": { 
        "path": "message", 
        "query": { 
        "bool": { 
         "must": [ 
          { 
           "match": { 
           "messages.message_text": "Banana" 
           } 
          } 
         ] 
        } 
        } 
       } 
      } 
     ] 
     } 
    } 
}' 
+0

Hata almaya devam ettiğim için orijinal gönderiimde bir değişiklik yaptım. –

İlgili konular