Elasticsearch查询具有多级子级的数据

时间:2017-05-16 07:38:02

标签: elasticsearch nosql

鉴于此样本数据:

"users": {
    "user1": {
         "first": "john",
         "last": "bellamy"
     },
    "user2": {
         .....
         .....
     }
 }

如何设置弹性搜索来查询/搜索儿童 first last ? Ohter教程只显示一个级别的孩子,而不是这个2级或更多级别的孩子。

我尝试寻找解决方案,我想这与mapping选项有关?

我刚刚开始使用elasticsearch,已经设法设置和添加数据。

1 个答案:

答案 0 :(得分:0)

这对我有用

{
    "mappings": {
        "test_type": {
            "properties": {
                "users": {
                    "type": "nested",
                    "properties": {
                        "firstname": {
                            "type": "text"
                        },
                        "lastname": {
                            "type": "text"
                        }
                    }
                }
            }
        }
    }
}

嵌套用户方法

映射

{
    "query": {
        "bool": {
            "must": [{
                "nested": {
                    "inner_hits": {},
                    "path": "users",
                    "query": {
                        "bool": {
                            "must": [{
                                "term": {
                                    "users.firstname": {
                                        "value": "ajay"
                                    }
                                }
                            }]
                        }
                    }
                }
            }]
        }
    }
}

查询

.box