【发布时间】:2019-07-26 03:16:31
【问题描述】:
在查询使用join 数据类型设置的索引时,我无法让has_parent 查询返回任何结果。我完全按照Elasticsearch's join datatype documentation page 上的示例进行操作:
添加一个索引,其中包含question(父)和answer(子)之间的连接:
PUT my_index
{
"settings": {
"mapping.single_type": true
},
"mappings": {
"doc": {
"properties": {
"my_join_field": {
"type": "join",
"relations": {
"question": "answer"
}
}
}
}
}
}
添加两个问题:
PUT my_index/doc/1?refresh
{
"text": "This is a question",
"my_join_field": {
"name": "question"
}
}
PUT my_index/doc/2?refresh
{
"text": "This is a another question",
"my_join_field": {
"name": "question"
}
}
添加两个答案:
PUT my_index/doc/3?routing=1&refresh
{
"text": "This is an answer",
"my_join_field": {
"name": "answer",
"parent": "1"
}
}
PUT my_index/doc/4?routing=1&refresh
{
"text": "This is another answer",
"my_join_field": {
"name": "answer",
"parent": "1"
}
}
该文档没有示例说明如何使用has_parent 查询来查询。这是我的尝试,基于the has_parent doc,但它没有返回任何结果:
GET my_index/_search
{
"query": {
"has_parent": {
"parent_type": "question",
"query" : {
"match" : { "text" : "another" }
}
}
}
}
即使这会返回一个问题和一个答案,正如预期的那样:
GET my_index/_search
{
"query": {
"match" : { "text" : "another" }
}
}
我使用的是 Elasticsearch 5.6.2。
【问题讨论】:
标签: elasticsearch elasticsearch-5