Anish
Anish

Reputation: 33

CKAN Datastore search for fetching particular fields not working

I created a CKAN datastore with below fields and data

"primary_key" : ["Book ID"],
        "fields" :[
            {"id":"Book ID","type":"number"},
            {"id":"Book Name","type":"text"},
            {"id":"Author","type":"text"},
            {"id":"Publications","type":"text"},
            {"id":"Price","type":"text"},
            {"id":"Discount","type":"text"}

        ],
        "records": [ 
                    {   "Book ID" :"1",
                        "Book Name" :"Book1",
                        "Author" :"Author1",
                        "Publications" :"Pub1",
                        "Price" :"895",
                        "Discount" :"5"
                    },
                    {   "Book ID" :"2",
                        "Book Name" :"Book2",
                        "Author" :"Author2",
                        "Publications" :"Pub2",
                        "Price" :"699",
                        "Discount" :"5"
                    },
                    {   "Book ID" :"3",
                        "Book Name" :"Book3",
                        "Author" :"Author3",
                        "Publications" :"Pub3",
                        "Price" :"500",
                        "Discount" :"10"
}]

I need to fetch some particular fields. I use datastore_search and i gave fields i need to fetch. But it shows error.

My search code :

{ "resource_id": "740d27f5-790c-43d8-9d5d-23c8aab9303e", 
"fields": [
{ "id": "Book Name"},
{ "id": "Author"}
],
"filters": {"Book Name": "Book1"}
}

Upvotes: 3

Views: 242

Answers (1)

Praveen S
Praveen S

Reputation: 395

The "fields" are list or comma separated string and here you gave fields as array of object.

Try this code:

   {
      "resource_id": "740d27f5-790c-43d8-9d5d-23c8aab9303e", 
      "fields": "Book Name,Author",
      "filters": {"Book Name": "Book1"}
    }

Upvotes: 1

Related Questions