Kuzzle create index with mapping when importing CSV date fields

Viewed 46

I have a CSV file with:

fname,lname,age,phone,address,dob
chris,jack,51,656-724-7821,aaaaa,03/01/2016 12:00:01 AM
joe,freds,44,545-724-7821,fsdfds sdfsdfsf sdfsdf,03/01/2015 12:00:01 AM

and a mapping defined as:

const new1Mappings = {
        properties: {
            fname: {
                "type": "text"
            },
            lname: {
                "type": "text"
            },
            age: {
                "type": "integer"
            },
            phone: {
                "type": "text"
            },
            address: {
                "type": "text"
            },
            dob: {
                "type": "text" <----- issue is here
            }
        }
    };

Now using the Kuzzle API to import the CSV:

await kuzzle.collection.create('new1', 'contacts', new1Mappings);
await kuzzle.bulk.mWrite('new1', 'contacts', data); // data is an array built from the contents of the CSV file

When I set the mapping type for the "dob" field to "text" the collection document is created but is not searchable as a date field. If I change the mapping type for "dob" to "date" then no documents are created in the collection.

What mapping data type should a CSV date field be specified as?

2 Answers

I was passing in an incorrect date time string format.

chris,jack,51,656-724-7821,aaaaa,03/01/2016 12:00:01 AM

for

dob: {
         "type": "text" <----- issue is here
     }

So I changed the CSV to

chris,jackson,51,444-555-555,aaaaa,2021-01-01 01:00:00

and the mapping to

dob: {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss"
     }

All good now.

Related