Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/scheme/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch 具有多级子级数据的Elasticsearch查询_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Nosql - Fatal编程技术网 elasticsearch 具有多级子级数据的Elasticsearch查询,elasticsearch,nosql,elasticsearch,Nosql" /> elasticsearch 具有多级子级数据的Elasticsearch查询,elasticsearch,nosql,elasticsearch,Nosql" />

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

elasticsearch 具有多级子级数据的Elasticsearch查询,elasticsearch,nosql,elasticsearch,Nosql,鉴于此示例数据: "users": { "user1": { "first": "john", "last": "bellamy" }, "user2": { ..... ..... } } 我如何设置elasticsearch来查询/搜索子第一个和最后一个?Ohter教程仅显示一个级别的子级,而不是这两个或更多级别的子级 我试着寻找一个解决方案,我猜它与映射选项有关 我几天前刚开始e

鉴于此示例数据:

"users": {
    "user1": {
         "first": "john",
         "last": "bellamy"
     },
    "user2": {
         .....
         .....
     }
 }
我如何设置elasticsearch来查询/搜索子
第一个
最后一个
?Ohter教程仅显示一个级别的子级,而不是这两个或更多级别的子级

我试着寻找一个解决方案,我猜它与
映射
选项有关

我几天前刚开始elasticsearch,已经成功地设置和添加了数据。

这对我很有用

{
    "query": {
        "bool": {
            "must": [{
                "term": {
                    "users.user2.firstname": {
                        "value": "sumit"
                    }
                }
            }]
        }
    }
}
嵌套用户方法

映射

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

这对我有用

{
    "query": {
        "bool": {
            "must": [{
                "term": {
                    "users.user2.firstname": {
                        "value": "sumit"
                    }
                }
            }]
        }
    }
}
嵌套用户方法

映射

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


用户不是嵌套的类型或密钥散列?@user3775217我不这么认为,因为
users
不是数组。
users不是嵌套的类型或密钥散列?@user3775217我不这么认为,因为
users
不是数组。
user1
user2
(又称userId)是我想返回的问题,我想这样使用它:
找到名为john的用户
->然后重新访问userId因为user1和user2是用户,您可以将用户作为嵌套对象,然后使用嵌套的内部hit这里的问题是
user1
user2
(又称userId)是我想要返回的问题,我想这样使用它:
找到名为john的用户
->然后重新访问userid因为user1和user2是用户,您可以将用户设置为嵌套对象,然后使用嵌套的innerhits