弹性搜索嵌套数组查询

时间:2016-08-22 20:05:39

标签: elasticsearch nested

我有以下架构弹性搜索: 为了便于阅读,我缩写了大部分内容

       {
   "took": 56,
   "timed_out": false,

   "hits": {

      "hits": [

         {
             "_id": "2FREAL%2FShaarHanegev%2Faxis-ACCC8E43E0C6%2F20160314%2F16%2F20160314_164253_E23D_ACCC8E43E0C6%2F20160314_16%2F20160314_164253_8DA7_ACCC8E43E0C6.mkv%3A26.153_1508_1439_1763_1440",
            "_source": {
               "path": "2FREAL%2FShaar%2Faxis-ACCC8E43E0C6%2F20160314%2F16%2F20160314_164253_E23D_ACCC8E43E0C6%2F20160314_16%2F20160314_164253_8DA7_ACCC8E43E0C6.mkv%3A26.153_1508_1439_1763_1440",
              "frameAttributes": {

                  "trackerId": "OB7E600",

                  "identities": [
                     {
                        "_id": "Abel_Nachos_034841460",
                        "_score": 0.451906
                     },
                     {
                        "_id": "judas_acorn_10000897",
                        "_score": 0.430024
                     },
                     {
                        "_id": "regenald_barbish_10000452",
                        "_score": 0.41979
                     },
                     {
                        "_id": "Matthew_Gordon_Douglas_0631B#1",
                        "_score": 0.412086
                     },
                     {
                        "_id": "NewYork_NYC_Gina_Lob_10000566",
                        "_score": 0.407909
                     }
                  ]
               },
               "originalVideoFullPath": "REAL/Shaar/axis-ACCC8E43E0C6/20160314/16/20160314_164253_E23D_ACCC8E43E0C6/20160314_16/20160314_164253_8DA7_ACCC8E43E0C6.mkv"
            }
         },
         {

            "_id": "2FREAL%2FShaar%2Faxis-ACCC8E43E0C6%2F20160314%2F16%2F20160314_164253_E23D_ACCC8E43E0C6%2F20160314_16%2F20160314_164253_8DA7_ACCC8E43E0C6.mkv%3A26.393_1454_1457_1711_1454",

            "_source": {
               "path": "2FREAL%2FShaarHanegev%2Faxis-ACCC8E43E0C6%2F20160314%2F16%2F20160314_164253_E23D_ACCC8E43E0C6%2F20160314_16%2F20160314_164253_8DA7_ACCC8E43E0C6.mkv%3A26.393_1454_1457_1711_1454",

                "frameAttributes": {
                   "trackerId": "OB7E600",

                  "identities": [
                     {
                        "_id": "Levon_Ayrapetyan_10000036",
                        "_score": 0.432837
                     },
                     {
                        "_id": "Patrick_sole_10001145",
                        "_score": 0.425161
                     },
                     {
                        "_id": "TAI_YUNG_LEE_LOUIE_10002450",
                        "_score": 0.404628
                     },
                     {
                        "_id": "Izak_Gold_10000159",
                        "_score": 0.400651
                     },
                     {
                        "_id": "Takahiro_Friend_10001663",
                        "_score": 0.392012
                     }
                  ]
               },
               "clockwiseRotation": 90,
               "numberOfFrames": 0,
               "originalVideoFullPath": "REAL/Shaar/axis-ACCC8E43E0C6/20160314/16/20160314_164253_E23D_ACCC8E43E0C6/20160314_16/20160314_164253_8DA7_ACCC8E43E0C6.mkv"
            }
         }

      ]
   }
}

编辑:我按要求添加了缩写映射

    {
  "index1": {
    "mappings": {
      "objects": {
        "properties": {
          "_results": {
            "type": "object"
          },
          "cameraId": {
            "type": "string"
          },
          "cameraType": {
            "type": "string"
          },
          "date": {
            "type": "date",
            "format": "dateOptionalTime"
          },
          "frameAttributes": {
            "properties": {
              "identities": {
                "properties": {
                  "_id": {
                    "type": "string"
                  },
                  "_score": {
                    "type": "double"
                  }
                }
              },
              "testPassed": {
                "type": "boolean"
              }
            }
          },
          "fraudType": {
            "type": "string"
          },
          "index": {
            "type": "long"
          },
          "path": {
            "type": "string"
          },
          "siteName": {
            "type": "string",
            "index": "not_analyzed"
          }
        }
      }
    }
  }
}

我正在尝试编写一个查询,找到人{NewYork_NYC_Gina_Lob_10000566}所在的所有视频(ID)。

1 个答案:

答案 0 :(得分:0)

我没有看到映射,所以这是一个忽略可能的嵌套对象或父子关系的查询。

GET your_index/_search 
{
"query": {
    "bool": {
        "must": [
            {
              "term": {
                "frameAttributes.identities._id": "NewYork_NYC_Gina_Lob_10000566"
              }
            }
        ]
    }
  } 
}