CollectionMapping

/*
 Constructors are not exposed in the JS/Node SDK.
 CollectionMapping objects are returned by the method
 Collection.getMapping

 You may also use the Collection.collectionMapping() method:
 */
var mapping = kuzzle.collection('collection', 'index').collectionMapping();

mapping = kuzzle.collection('collection', 'index').collectionMapping(mapping);
CollectionMapping dataMapping = new CollectionMapping(dataCollection);

JSONObject mapping = new JSONObject();
JSONObject type = new JSONObject();
type.put("type", "string");
mapping.put("foo", type);

CollectionMapping dataMapping = new CollectionMapping(dataCollection, mapping);
<?php

use \Kuzzle\Kuzzle;
use \Kuzzle\DataMapping;

$mapping = [
  'someField' => [
    'type' => 'string',
    'index' => 'analyzed'
  ]
];

$kuzzle = new Kuzzle('localhost');
$dataCollection = $kuzzle->collection('collection', 'index');

$dataMapping = $dataCollection->collectionMapping($mapping);
// $dataMapping instanceof DataMapping

When creating a new data collection in the persistent data storage layer, Kuzzle uses a default mapping. It means that, by default, you won't be able to exploit the full capabilities of our persistent data storage layer (currently handled by ElasticSearch), and your searches may suffer from below-average performances, depending on the amount of data you stored in a collection and the complexity of your database.

The CollectionMapping object allow to get the current mapping of a data collection and to modify it if needed.


CollectionMapping(Collection, [mapping])

ArgumentsTypeDescription
CollectionCollectionAn instantiated Collection object
mappingJSON ObjectOptional mapping

Properties

Property nameTypeDescriptionget/set
headersJSON ObjectCommon headers for all sent documents.get/set
mappingobjectEasy-to-understand list of mappings per fieldget/set

Note: the headers property is inherited from the provided Collection object and can be overrided