【发布时间】:2019-01-11 11:29:39
【问题描述】:
我有如下 post_filter,我试图过滤学校名称为 HILL SCHOOL AND 的记录,其中包含名为 JOY AND 部分 A 的嵌套子对象.
school 存在于父对象中,它包含嵌套对象的子列表。
以上都是AND条件。
但查询似乎不起作用。知道为什么吗?有没有办法将两个嵌套查询结合起来?
GET /test_school/_search
{
"query": {
"match_all": {}
},
"post_filter": {
"bool": {
"must_not": [
{
"bool": {
"must": [
{
"term": {
"schoolname": {
"value": "HILL SCHOOL"
}
}
},
{
"nested": {
"path": "children",
"query": {
"bool": {
"must": [
{
"match": {
"name": "JACK"
}
}
]
}
}
}
},
{
"term": {
"children.section": {
"value": "A"
}
}
}
]
}
}
]
}
}
}
架构如下:
PUT /test_school
{
"mappings": {
"_doc": {
"properties": {
"schoolname": {
"type": "keyword"
},
"children": {
"type": "nested",
"properties": {
"name": {
"type": "keyword",
"index": true
},
"section": {
"type": "keyword",
"index": true
}
}
}
}
}
}
}
示例数据如下:
POST /test_school/_doc
{
"schoolname":"HILL SCHOOL",
"children":{
"name":"JOY",
"section":"A"
}
}
第二条记录
POST /test_school/_doc
{
"schoolname":"HILL SCHOOL",
"children":{
"name":"JACK",
"section":"B"
}
}
【问题讨论】:
-
您能否提供索引
http://localhost:9200/<ur_index_name>/_mapping的映射,并尝试在school字段的查询中将term更改为match。 -
如果
children.section是text类型,那么问题可能在于A是在分析过程中被删除的停用词。如果你有“children.section.keyword”,你可能想使用那个字段 -
@AmitKhandelwal 已更新架构。
-
@Val 字段被标记为关键字已添加架构。
-
当您说“它似乎不起作用”时,您是什么意思?一个错误?没有结果?错误的结果?请详细说明。
标签: elasticsearch