【发布时间】:2014-12-03 04:41:37
【问题描述】:
我正在尝试通过一个简单的示例应用程序来学习弹性搜索,该示例应用程序列出了与人相关的引用。示例映射可能如下所示:
{
"people" : {
"properties" : {
"name" : { "type" : "string"},
"quotations" : { "type" : "string" }
}
}
}
一些示例数据可能如下所示:
{ "name" : "Mr A",
"quotations" : [ "quotation one, this and that and these"
, "quotation two, those and that"]
}
{ "name" : "Mr B",
"quotations" : [ "quotation three, this and that"
, "quotation four, those and these"]
}
我希望能够在个别报价上使用查询字符串 api,并返回匹配的人。例如,我可能想找到引用包含(this AND these)的人——应该返回“Mr A”而不是“Mr B”,等等。我怎样才能做到这一点?
编辑1:
Andrei 在下面的回答似乎有效,数据值现在看起来像:
{"name":"Mr A","quotations":[{"value" : "quotation one, this and that and these"}, {"value" : "quotation two, those and that"}]}
但是,我似乎无法让 query_string 查询工作。以下不产生任何结果:
{
"query": {
"nested": {
"path": "quotations",
"query": {
"query_string": {
"default_field": "quotations",
"query": "quotations.value:this AND these"
}
}
}
}
}
有没有办法让 query_string 查询与嵌套对象一起工作?
Edit2:是的,请参阅 Andrei 的回答。
【问题讨论】:
标签: elasticsearch