Reputation: 265
I have created index using this post request payload :
{
"index": {
"fields": [
"sortdate","coordinates"
]
},
"type": "json"
}
and index created successfully. Now i fetch the record using this post request URL
Payload:
{
"selector": {
"coordinates": [18.497484,73.81349]
},
"sort": [
{
"sortdate": "asc"
}
]
}
and getting following response:
{
"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
}
]
}
As you can see record are not coming sorted as per sortdate field.
I am not getting what is wrong here.
Upvotes: 0
Views: 148
Reputation: 5637
When you instruct Cloudant to create an index from the fields "sortdate","coordinates", it creates an data structure on disk ordered by sortdate
and coordinates
. If you subsequently perform a query that can be optimised using this index then your query will be get a performance boost.
Unfortunately, the query you are making is not helped by the index you created. Querying by coordinates
on its own is helped by an index on sortdate & coordinates.
Your query may be boosted by an index on coordinates
on its own e.g.
{
"index": {
"fields": [
"sortdate","coordinates"
]
},
"type": "json"
}
Upvotes: 1