0

How would I add a JSON to elastic search using Elastica for pHp? I don't want to have an index and mapping automatically generated as the number of fields in the JSON is massive. I've searched far and wide and have not found a simple example for a JSON without an index and mapping. I just want to be able to do some simple searches for now as I am just learning. A complete example here or somewhere else on the web would be highly appreciated.

John
  • 3,037
  • 8
  • 36
  • 68

1 Answers1

0

An index in elastic search can have multiple types which are stored (and indexed) within it. You are probably going to want to consider your JSON document as one type to start with.

You can define what fields are indexed for that type using a mapping. In Elastica, a mapping is encapsulated in a Elastica\Type\Mapping class. Instantiate a new mapping object and set your type type against that object - $mapping->setType($type);

You can then set the fields you want to index and describe how you want to index them -

$mapping->setProperties(array(
    'name' => array('type' => 'string')
));

The elastica documentation provides good examples of using the Mapping class to define how your types are mapped. See the 'Define Mapping' section here.

Hope that's useful

Rob Squires
  • 2,108
  • 16
  • 15