2

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?

Chris Jackson
  • 718
  • 1
  • 6
  • 14

2 Answers2

3

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.

E.Berthier
  • 83
  • 5
0

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.

Chris Jackson
  • 718
  • 1
  • 6
  • 14