我正在尝试使用mongoid- elasticsearch 和 ElasticSearch 2.0 在嵌套字段上应用术语查询。这变得非常令人沮丧,因为试错并没有带来太多回报,而且有关该主题的文档也很少。这是我的查询:
{
"query": {
"nested": {
"path": "awards",
"query": {
"bool": {
"must": [
{ "match": { "awards.year": "2010"}}
]
}
}
},
"nested":{
"path": "procuring_entity",
"query": {
"bool": {
"must": [
{ "terms": { "procuring_entity.country": ["ES", "PL"]}}
]
}
}
}
}
}
虽然“匹配”和“术语”工作得很好,但当与“术语”查询结合使用时,它不会返回任何结果,甚至认为它应该返回。我的映射如下所示:
elasticsearch!({
prefix_name: false,
index_name: 'documents',
index_options: {
mappings: {
document: {
properties: {
procuring_entity: {
type: "nested"
},
awards: {
type: "nested"
}
}
}
}
},
wrapper: :load
})
如果“嵌套”不算作分析器(据我所知不算),那没有问题。至于第二个例子,我认为不是这样,因为它匹配的值数组来自外部。是否可以在嵌套字段上进行术语查询?难道我做错了什么?有没有其他方法可以将嵌套字段与多个值匹配?
任何想法将不胜感激。