简体   繁体   English

如何使用弹性搜索查询对象的键?

[英]How to query keys of objects using Elastic Search?

Hi my data is structured in the following manner: 嗨,我的数据以以下方式进行结构化:

student{
 subjects{
   biology:{
     0: "A2-Level"
     1:"AS-Level"
     2:"University"
  }
 }
}

My main index is at student, therefore my properties are as follows 我的主要指标是学生,因此我的属性如下

"mappings":{"student":{"properties":{"subjects":{"type":"nested","properties":{"biology":{"type":"string"},"english":{"type":"string"}}}

Im currently doing this search : 我目前正在搜索:

    var query = {
          index: 'firebase',
          type: 'student',
          "body": {
            "query": {
              "bool": {
                "must": [ 
       {
        "nested": {
          "path": "subjects",
          "query": {
            "bool": {
              "must": [
                { "exists": { "field": english } }
              ]
            }
          }
        }
      }

    ]

to return the students that are studying english. 返回正在学习英语的学生。 However nothing is being returned? 但是什么都没有退还? Can anyone suggest where I am going wrong? 谁能建议我要去哪里错了?

You should check for subjects.english field instead of english So, your query should look something like this: 您应该检查subject.english字段而不是english,因此,您的查询应类似于以下内容:

{
"query": {
  "bool": {
     "must": [
        {
           "nested": {
              "path": "subjects",
              "query": {
                 "bool": {
                    "must": [
                       {
                          "exists": {
                             "field": "subjects.english"
                          }
                       }
                    ]
                 }
              }
           }
        }
     ]
  }
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM