2016-02-08 3 views
0

Имея следующее отображение ...Elasticsearch проблема детей-отец с 'has_parent'

curl -XPUT 'localhost:9200/myindex' -d '{ 
    "mappings": { 
    "my_parent": {}, 
    "my_child": { 
     "_parent": { 
     "type": "my_parent" 
}}}}' 

... следующий родитель:

curl -X PUT localhost:9200/myindex/my_parent/1?pretty=true' -d '{ 
    "title" : "Microsiervos - Discos duros de 10TB", 
    "body" : "Empiezan a sacar DD de 30GB en el mercado" 
}' 

и следующие дети:

curl -XPUT 'localhost:9200/myindex/my_child/2?parent=1' -d '{ 
    "user": "Pepe" 
}' 

Если я сделаю следующее: has_child запрос:

curl -XGET 'localhost:9200/myindex/my_parent/_search?pretty=true' -d '{ 
    "query": { 
    "has_child": { 
     "type": "my_child", 
     "query" : { 
      "query_string" : { 
       "default_field" : "user", 
       "query" : "Pepe" 
}}}}}' 

Я получаю желаемый результат. Pepe найден, и его отец показано:

"hits" : { 
    "total" : 1, 
    "max_score" : 1.0, 
    "hits" : [ { 
     "_index" : "myindex", 
     "_type" : "my_parent", 
     "_id" : "2", 
     "_score" : 1.0, 
     "_source":{ 
    "title" : "Microsiervos - En el 69 llegamos a la luna", 
    "body" : "Se cumplen 3123 anos de la llegada a la luna" 
} 

Но если я попытаюсь сделать это в обратном направлении, пытаясь получить дети с помощью has_parent:

curl -XGET 'localhost:9200/myindex/my_parent/_search?pretty=true' -d '{ 
    "query": { 
    "has_parent": { 
     "parent_type": "my_parent", 
     "query" : { 
      "query_string" : { 
       "default_field" : "body", 
       "query" : "mercado" 
}}}}}' 

я не получаю никаких ударов. Я предполагал получить в качестве выходных данных Pepe. Что мне не хватает или что-то не так?

PS: Я использую Elasticsearch 2.1.1

ответ

1

Вы совершили ошибку above.You искомая в my_parent типа. Если вы хотите получить детей с использованием родительского, вы должны получить его от child_type. Изменить запрос на:

curl -XGET 'localhost:9200/myindex/my_child/_search?pretty=true' -d  
'{ 
"query": { 
"has_parent": { 
    "parent_type": "my_parent", 
    "query" : { 
     "query_string" : { 
      "default_field" : "body", 
      "query" : "mercado" 
     } 
    } 
    } 
} 
}' 

Пожалуйста, обратите внимание, я использовал

curl -XGET 'localhost:9200/myindex/my_child/_search?pretty=true' 

вместо

curl -XGET 'localhost:9200/myindex/my_parent/_search?pretty=true' 
Смежные вопросы