我有以下结构:搜索特定的字段作为一个文档
{
"mappings": {
"document": {
"properties": {
"title": {
"type": "string"
},
"paragraphs": {
"type": "nested",
"properties": {
"paragraph": {
"type" : "object",
"properties" : {
"content": { "type": "string"},
"number":{"type":"integer"}
}
}
}
}
}
}
}
}
有了这些样本文件
{
"title":"Dubai seeks cause of massive hotel fire at New Year",
"paragraphs":[
{"paragraph": {"number": "1", "content":"Firefighters managed to subdue the blaze, but part of the Address Downtown Hotel is still smouldering."}},
{"paragraph": {"number": "2", "content":"A BBC reporter says a significant fire is still visible on the 20th floor, where the blaze apparently started."}},
{"paragraph": {"number": "3", "content":"The tower was evacuated and 16 people were hurt. But a fireworks show went ahead at the Burj Khalifa tower nearby."}},
{"paragraph": {"number": "4", "content":"The Burj Khalifa is the world's tallest building and an iconic symbol of the United Arab Emirates (UAE)."}}]
}
{
"title":"Munich not under imminent IS threat",
"paragraphs":[{"paragraph": {"number": "1", "content":"German officials say there is no sign of any imminent terror attack, after an alert that shut down two Munich railway stations on New Year's Eve."}}]
}
我现在可以搜索使用每个段落
{
"query": {
"nested": {
"path": "paragraphs", "query": {
"query_string": {
"default_field": "paragraphs.paragraph.content",
"query": "Firefighters AND still"
}
}
}
}
}
问题:我怎样才能查询一个查询几个p aragraphs但只有内容字段?
这工作,但搜索所有领域
{
"query": {
"query_string": {
"query": "Firefighters AND apparently AND 1"
}
}
}
它匹配消防队员从第1款和显然第2款的,我想。然而我不想因为它不是一个内容字段而被匹配。
澄清:第一个搜索按照我想要的段落进行搜索。不过,我也希望能够搜索整个文档(所有段落)。
解决方案 我补充说:“include_in_parent”:真实的,因为它在https://www.elastic.co/guide/en/elasticsearch/reference/1.7/mapping-nested-type.html
你的第一个查询有什么问题?是不是经历了所有段落? – ChintanShah25
是。但我也希望选择同时搜索所有段落,以便“消防员显然”会返回文档,即使它们处于不同的段落中 – user568327
您可以尝试编写脚本。 – Ashalynd