ElasticSearch,从资产中搜索最大ID

问题描述 投票:0回答:1

我在从资产中找到最大值时遇到问题。我的问题是找到ImageId的最大值。

{
    "_index": "b885a88d-7f55-5841-8166-77c948cff307",
    "_type": "_doc",
    "_id": "0a714077-83c0-4d5f-a1d5-88b3f3689b34",
    "_version": 2,
    "_seq_no": 5443,
    "_primary_term": 1,
    "found": true,
    "_source": {
        "created": "2020-01-31T15:01",
        "assetId": "0a714077-83c0-4d5f-a1d5-88b8f3689b34",
        "properties": [
            {
                "uuid": "e2f9e990-aa6e-4122-87fb-1b98307d7d58",
                "name": "imageId",
                "namespace": "file.Jpeg",
                "value": "123456"
            },
            {
                "uuid": "bc506442-90a6-41fc-a36b-2970f202988d",
                "name": "tmpName",
                "namespace": "file.Jpeg",
                "value": "/tmp/phpQIqVPk"
            },
            {
                "uuid": "6b3a2624-adf3-449b-a6c9-883396f98538",
                "name": "type",
                "namespace": "file.Jpeg",
                "value": "image/jpeg"
            },
            {
                "uuid": "3cf1be43-d0e8-4bb1-8c16-6f05a99d55f6",
                "name": "size",
                "namespace": "file.Jpeg",
                "value": "6605"
            },
        ],
        "asset_child_references": [],
        "asset_parent_references": []
    }
}

我尝试过这个

{"query":{"match":{"properties.name":"imageId"}},
"sort": [
    {
      "properties.value": {
        "order": "desc"
      }
    }
  ],
   "size": 1
}

但它会检查每个值参数。如何只检查imageId中的value参数?

感谢您的帮助。

elasticsearch search assets
1个回答
0
投票

我找到了解决方案。 Elasticsearch中的数组必须嵌套。

我在Elsaticsearch上找到了这个:

对象数组无法按预期工作:您不能独立于数组中的其他对象查询每个对象。如果需要执行此操作,则应使用嵌套数据类型而不是对象数据类型。

现在我已经嵌套了我的数据。

    {
        "mappings": {
            "properties": {
                "properties": {
                    "type": "nested" 
                }
            }
        }
    }

我希望这会对其他用户有所帮助:-)

© www.soinside.com 2019 - 2024. All rights reserved.