2

Using the kuzzle.collection.create('abc123', 'yellow-taxi', {definition});

to create a collection on an index. The collection gets created but the mappings arent applied.

Here is the code im using

const definition = {
    mappings: {
        dynamic: "true",
        properties: {
            VendorID: {
                "type": "integer"
            },
            tpep_pickup_datetime: {
                "type": "date"
            },
            ........
        }
    },
    settings: {
    }
};

try {
    // Creates a collection
    await kuzzle.collection.create('abc123', 'yellow-taxi', {definition});
    // await kuzzle.collection.create('abc123', 'yellow-taxi');
    console.log('Collection');
} catch (error) {
    console.error(error.message);
}

Here is the kuzzle documentation referance im using

https://docs.kuzzle.io/sdk/js/7/controllers/collection/create/#usage

enter image description here

After kuzzle.create - I run

const mapping = await kuzzle.collection.getMapping('abc123', 'yellow-taxi');
            console.log('mapping: ', mapping);

mapping:  { dynamic: 'false', properties: {} }
Chris Jackson
  • 718
  • 1
  • 6
  • 14

2 Answers2

3

The way you are passing the mappings are not correct, you pass a POJO containing a definition property who contains the mappings. You should pass the definition object directly.

// don't
console.log({ definition }); // { definition: { mappings: ..., settings: ... } }

// do
console.log(definition); // { mappings: ..., settings: ... } 

await kuzzle.collection.create('abc123', 'yellow-taxi', definition);
Aschen
  • 1,691
  • 11
  • 15
  • When I use await kuzzle.collection.create('abc123', 'yellow-taxi', definition); Without the curley brackets, the mappings are saved but no documents. The collection is empty. – Chris Jackson Apr 08 '21 at 12:22
2

Ok, after a bit I decided to build my own CSV file with a few fields and make a new mappings definition. This worked. So it looks like my mappings definition for the yellow-taxi collection I had had something wrong.

kuzzle.collection.create('abc123', 'yellow-taxi', definition);

didn't give any notice of mappings issues.

My mappings for the CSV data were wrong.

Chris Jackson
  • 718
  • 1
  • 6
  • 14