【发布时间】:2016-03-01 11:55:50
【问题描述】:
我有以下结构(一个非常大的弹性搜索文档的一小部分)
sample: {
{
"md5sum":"4002cbda13066720513d1c9d55dba809",
"id":1,
"sha256sum":"1c6e77ec49413bf7043af2058f147fb147c4ee741fb478872f072d063f2338c5",
"sha1sum":"ba1e6e9a849fb4e13e92b33d023d40a0f105f908",
"created_at":"2016-02-02T14:25:19+00:00",
"updated_at":"2016-02-11T20:43:22+00:00",
"file_size":188416,
"type":{
"name":"EXE"
},
"tags":[
],
"sampleSources":[
{
"filename":"4002cbda13066720513d1c9d55dba809",
"source":{
"name":"default"
}
},
{
"filename":"4002cbda13066720332513d1c9d55dba809",
"source":{
"name":"default"
}
}
]
}
}
我想使用的过滤器是使用弹性搜索通过 sample.sampleSources.source 中包含的“名称”来查找。
我尝试了以下查询
curl -XGET "http://localhost:9200/app/sample/_search?pretty" -d {query}
其中,{query} 是
{
"query":{
"nested":{
"path":"sample.sampleSources",
"query":{
"nested":{
"path":"sample.sampleSources.source",
"query":{
"match":{
"sample.sampleSources.source.name":"default"
}
}
}
}
}
}
}
但是,它没有返回任何结果。我的文档中有某些情况,其中嵌套比这更深。有人可以指导我如何制定此查询以使其适用于所有情况吗?
编辑 1 映射:
{
"app":{
"mappings":{
"sample":{
"sampleSources":{
"type":"nested",
"properties":{
"filename":{
"type":"string"
},
"source":{
"type":"nested",
"properties":{
"name":{
"type":"string"
}
}
}
}
}
}
编辑 2 下面 Waldemar Neto 发布的解决方案适用于 match query,但不适用于 a wild-card or neither for a regexp
你能指导一下吗?我需要通配符和正则表达式查询才能为此工作。
【问题讨论】:
-
请显示您的索引映射。
标签: elasticsearch