简体   繁体   中英

Query Orion Context Broker by Dates

I tried to query by dates interval in Orion 0.24 with no success.

A call to:

URL: http://<some-ip>:<some-port>/v2/entities?type=some-entity

Gives:

[
  {
    "id": "some-id",
    "type": "some-entity",
    "coordenadas": {
      "type": "geo:point",
      "value": "43.7723705, -7.6784461"
     },
     "fecha": {
       "type": "date",
       "value": "2015-08-21T22:00:00.000Z"
     },
 },
 {
    "id": "some-id",
    "type": "some-entity",
    "coordenadas": {
       "type": "geo:point",
       "value": "43.6850207, 7.5716216"
    },
    "fecha": {
        "type": "date",
        "value": "2015-09-09T22:00:00.000Z"
    }
  }
]

Then I query by dates interval in the following ways:

Call 1:

http://<some-ip>:<some-port>/v2/entities?type=some-entity&q=fecha==2015-08-01T22:00:00.000Z..2015-08-30T22:00:00.000Z

Call 2:

http://<some-ip>:<some-port>/v2/entities?type=some-entity&q=fecha==1441065601..1443657601

Both calls respond with a 200 code and payload []. I also tried other operators '>', '<' with the same result.

EDIT

I tried '==' over the property 'fecha' and works well:

Call 3:

http://<some-ip>:<some-port>/v2/entities?type=some-entity&q=fecha==2015-08-21T22:00:00.000Z

In the documentation says we can store dates, so I am doing so. Should I store them as numbers?

thanks

First of all, regarding documentation, I would like to remark the following comment at http://telefonicaid.github.io/fiware-orion/api/v2/ :

This is a work in progress and is changing on a daily basis

Which means that until NGSIv2 get completed, some desynchronization main occur between documentation and Orion implementation (documentation use to be more advanced that implementation).

Regarding this specific issue, the range, < and > filters will work at the end with Orion with dates, but not yet in 0.24.0. At 0.24.0 these filters only work with numbers, so, as temporal workaround you can store dates as timestamp numbers numbers (eg 2015-01-01 equals to 1420070400, the following page may help: http://www.timestampgenerator.com ).

EDIT : date filter support has been implemented in Orion 0.28.0 so from no on you can do queries like this one:

GET /v2/entities?q=birthdate>2016-02-24T10:00:00.00Z
GET /v2/entities?q=birthdate==2016-02-23T10:00:00.00Z..2016-02-24T10:00:00.00Z

Note also that you can use the dateCreated and dateModified to mean entity creation and modification time, eg:

GET /v2/entities?q=dateCreated>2016-02-24T10:00:00.00Z
GET /v2/entities?q=dateModified==2016-02-23T10:00:00.00Z..2016-02-24T10:00:00.00Z

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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