Search code examples
node.jscsvimportkuzzle

Kuzzle create index with mapping when importing CSV date fields


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?


Solution

  • You're right, to be able to search on the dob field as a date you'll need to set the type date in the mapping.

    Concerning the creation of the documents, your data need to fit with the Elasticsearch date type field data model.

    However, you might be able to adapt the mapping model using Elasticsearch Multi date format.