我似乎无法在弹性搜索中进行分面搜索
我似乎无法理解弹性搜索中面向方面的 QueryDSL。下面是我的查询对象以及 tags
数组的映射。我正在尝试将它们放入基于标签的多面导航中。每个“元素”将在标签数组中关联多个标签[并非所有元素都有标签。有些会有一个空数组。]。每个标签都是一个具有 id 和 tag 属性的对象。
我尝试过嵌套方面方法并收到“标签未嵌套”的错误,因此我在下面尝试此操作。我没有收到错误,但返回 JSON 中没有构面对象。我一直在使用此页面寻求帮助: http://www .elasticsearch.org/guide/reference/api/search/facets/index.html。
谁能帮助我正确格式化并理解它们的组织?我很感激任何帮助!
// this is my query object
{
"sort":{ "created_at":{ "order":"desc" } },
"query":{
"constant_score":{
"filter":{
"and":[
{ "missing":{ "field":"parent_id" } },
{ "missing":{ "field":"wall_id" } },
{ "term":{ "active":true } }
]
}
}
},
"facets":{
"tags":{ "terms":{ "field":"tags.tag" } }
}
}
// this is the mapping for the tags array
"tags":{
"type":"nested",
"include_in_parent":true,
"properties":{
"id":{ "type":"integer" },
"tag":{ "type":"string" }
}
},
I can't seem to understand the QueryDSL for facets in elastic search. Below are my query object, and the mapping for my tags
array. I'm trying to get these to put in a faceted navigation based on tags. Each "element" will have multiple tags associated in the tags array [Not all elements will have tags. Some will have an empty array.]. Each tag is an object with id and tag properties.
I've tried the nested facet approach and get the error that "tags is not nested", so then I try this below. I don't receive an error, but there is no facets object in the return JSON. I've been using this page for help: http://www.elasticsearch.org/guide/reference/api/search/facets/index.html.
Can anyone help me to format this correctly and understand the organization of these? I appreciate any help!
// this is my query object
{
"sort":{ "created_at":{ "order":"desc" } },
"query":{
"constant_score":{
"filter":{
"and":[
{ "missing":{ "field":"parent_id" } },
{ "missing":{ "field":"wall_id" } },
{ "term":{ "active":true } }
]
}
}
},
"facets":{
"tags":{ "terms":{ "field":"tags.tag" } }
}
}
// this is the mapping for the tags array
"tags":{
"type":"nested",
"include_in_parent":true,
"properties":{
"id":{ "type":"integer" },
"tag":{ "type":"string" }
}
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经尽力复制这个(使用0.18.5)但没有任何运气。下面是一些细节。第一个示例尝试复制您所描述的内容。第二个不将标签映射为 include_in_parent 并在构面请求中使用“嵌套”字段。正如您所看到的,在这两种情况下都会返回构面。
这使我相信其余映射存在问题,或者某些文档(不是您提供的示例文档)导致了问题。
当您尝试嵌套方法时,也许您使用了“nested”:“tags.tag”而不是“nested”:“tags”?
(Un)成功尝试#1:
使用映射创建索引:
}'
索引文档:
搜索:
结果:
(Un)成功尝试#2:
使用映射创建索引:
} '
索引文档:
搜索:
结果:
I've tried hard to replicate this (using 0.18.5) but without any luck. Some details below. The first example tries to replicate what you describe. The second doesn't map tags as include_in_parent and uses the "nested" field in the facet request. As you can see, in both cases the facet is returned.
This leads me to believe that there is either something wrong with the rest of the mappings or some document (not the sample one you provided) that is causing issues.
When you tried the nested approach, perhaps you used "nested":"tags.tag" instead of "nested":"tags"?
(Un)Successful attempt #1:
Create index with mappings:
}'
Index document:
Search:
Result:
(Un)Successful attempt #2:
Create index with mappings:
}'
Index document:
Search:
Result: