在ibm bluemix节点红色环境中排序不按预期工作

时间:2017-06-30 12:48:18

标签: couchdb ibm-cloud cloudant node-red

我使用this post request创建了索引 有效载荷:

{
  "index": {
    "fields": [

        "sortdate","coordinates"
            ]
      },
    "type": "json"
  }

并成功创建索引。 现在我使用this post request URL

获取记录

有效载荷:

{
  "selector": {
    "coordinates": [18.497484,73.81349]
  },
   "sort": [
    {
      "sortdate": "asc"
    }
  ]
}

并获得以下回复:

{
    "warning": "no matching index found, create an index to optimize query time",
    "docs": [
        {
            "_id": "4254f2d4638806b54802144ff25ecba7",
            "_rev": "1-6d3d573f21eb6d6518093aeb36a3ed5f",
            "aqi": 26,
            "coordinates": [
                18.497484,
                73.81349
            ],
            "so2": {
                "avg": 10,
                "aqi": 12
            },
            "pm10": {
                "avg": 26,
                "aqi": 26
            },
            "pm25": {
                "avg": 13,
                "aqi": 21
            },
            "date": "2017-06-30T11:08:45.439Z",
            "sortdate": 1498820925439
        },
        {
            "_id": "7c0278d8dfb3182c54ee1d6b03839b74",
            "_rev": "1-09d2b1354177f306b859f7f8c33d65d1",
            "aqi": 25,
            "coordinates": [
                18.497484,
                73.81349
            ],
            "so2": {
                "avg": 9,
                "aqi": 11
            },
            "pm10": {
                "avg": 25,
                "aqi": 25
            },
            "pm25": {
                "avg": 14,
                "aqi": 23
            },
            "date": "2017-06-30T09:56:55.004Z",
            "sortdate": 1498816615004
        },
        {
            "_id": "98e28cd2012a7c1b922f944162d12e00",
            "_rev": "1-b62d7c5fee4c9c9699cb7a9f950ec62c",
            "aqi": 25,
            "coordinates": [
                18.497484,
                73.81349
            ],
            "so2": {
                "avg": 9,
                "aqi": 11
            },
            "pm10": {
                "avg": 25,
                "aqi": 25
            },
            "pm25": {
                "avg": 14,
                "aqi": 23
            },
            "date": "2017-06-30T10:23:22.896Z",
            "sortdate": 1498818202896
        },
        {
            "_id": "cb6f3d1a313df7e95326d13085b480c9",
            "_rev": "1-77678d8df1c04dfc33f513906a97ca1e",
            "aqi": 26,
            "coordinates": [
                18.497484,
                73.81349
            ],
            "so2": {
                "avg": 10,
                "aqi": 12
            },
            "pm10": {
                "avg": 26,
                "aqi": 26
            },
            "pm25": {
                "avg": 13,
                "aqi": 21
            },
            "date": "2017-06-30T11:08:05.364Z",
            "sortdate": 1498820885364
        },
        {
            "_id": "db1fe2e2403f8acd8655a3a65cf4b36c",
            "_rev": "1-ef51370ef1ddc7215512b4644d095634",
            "aqi": 25,
            "coordinates": [
                18.497484,
                73.81349
            ],
            "so2": {
                "avg": 9,
                "aqi": 11
            },
            "pm10": {
                "avg": 25,
                "aqi": 25
            },
            "pm25": {
                "avg": 14,
                "aqi": 23
            },
            "date": "2017-06-30T09:42:40.284Z",
            "sortdate": 1498815760284
        },
        {
            "_id": "e226e828bce5e31534db87f44f98efae",
            "_rev": "1-2a238373a47575158866c56019d75fbe",
            "aqi": 25,
            "coordinates": [
                18.497484,
                73.81349
            ],
            "so2": {
                "avg": 9,
                "aqi": 11
            },
            "pm10": {
                "avg": 25,
                "aqi": 25
            },
            "pm25": {
                "avg": 14,
                "aqi": 23
            },
            "date": "2017-06-30T09:43:18.894Z",
            "sortdate": 1498815798894
        },
        {
            "_id": "e38663621c6148952fd84e3ab54195c0",
            "_rev": "1-fa45393376d7dc8677ebd48bd2804d70",
            "aqi": 26,
            "coordinates": [
                18.497484,
                73.81349
            ],
            "so2": {
                "avg": 10,
                "aqi": 12
            },
            "pm10": {
                "avg": 26,
                "aqi": 26
            },
            "pm25": {
                "avg": 14,
                "aqi": 23
            },
            "date": "2017-06-30T10:25:17.277Z",
            "sortdate": 1498818317277
        },
        {
            "_id": "e435e43de6bcb01c1596874afacef581",
            "_rev": "1-072be28b4128118e443c500494f456a1",
            "aqi": 26,
            "coordinates": [
                18.497484,
                73.81349
            ],
            "so2": {
                "avg": 10,
                "aqi": 12
            },
            "pm10": {
                "avg": 26,
                "aqi": 26
            },
            "pm25": {
                "avg": 13,
                "aqi": 21
            },
            "date": "2017-06-30T11:59:21.235Z",
            "sortdate": 1498823961235
        },
        {
            "_id": "f195832354b6fc816e1039dacf41546f",
            "_rev": "1-52fa322d3c034ddf70259991ac7c7021",
            "aqi": 26,
            "coordinates": [
                18.497484,
                73.81349
            ],
            "so2": {
                "avg": 10,
                "aqi": 12
            },
            "pm10": {
                "avg": 26,
                "aqi": 26
            },
            "pm25": {
                "avg": 14,
                "aqi": 23
            },
            "date": "2017-06-30T10:24:01.539Z",
            "sortdate": 1498818241539
        }
    ]
}

正如您所见,记录未按sortdate字段排序。

我在这里没有弄错。

1 个答案:

答案 0 :(得分:1)

当您指示Cloudant从字段" sortdate"," coordinates"创建索引时,它会在sortdate和{{1}排序的磁盘上创建数据结构}}。如果您随后执行可以使用此索引进行优化的查询,那么您的查询将获得性能提升。

不幸的是,您创建的索引没有帮助您创建的查询。 sortdate& amp;的索引有助于coordinates自己查询。坐标。

您的查询可以通过coordinates上的索引自行提升,例如

coordinates