NAME

ElasticSearchX::Model::Generator - Create a suite of ESX::Model classes from an existing mapping.

VERSION

version 0.1.8

SYNOPSIS

use ElasticSearchX::Model::Generator qw( generate_model );

my $instance = generate_model(
  mapping_url => 'http://someserver:port/path/_mapping',
  generated_base_class => 'MyModel',
  base_dir => "../path/to/export/dir/"
);

for my $document ( $instance->documents ) {
  # Write the document to disk
  $document->write();
  # Alternatively, load the generated document into memory avoiding writing to disk
  $document->evaluate();
}

DESCRIPTION

ALPHA Code: This class at present only contains code sufficient for very simple package generation for use in creating a model from an existing mapping for the purposes of search.

EXPORTS

generate_model

this is just a sugar syntax for ESX:M:G->new() you can elect to import to make your code slightly shorter.

METHODS

index_names

@names = $esmg->index_names

returns the names of all indexes specified in the _mapping

index

$data = $esmg->index('') # If indexes are not in the data set
$data = $esmg->index('cpan_v1') # if indexes are in the data set

Returns the data set nested under the specified index.

type_names

@names = $esmg->type_names( $index )
@names = $esmg->type_names('')  # return all types defined in an index-free dataset.
@names = $esmg->type_names('cpan_v1') # return all types in the cpan_v1 index.

type

$data = $esmg->type( $index, $type )
$data = $esmg->type( '', 'File' )    # get type 'File' from an index-free dataset
$data = $esmg->type( 'cpan_v1', 'File' )    # get type 'File' from the cpan_v1 index

property_names

@names = $esmg->property_names( $index, $type )

properties

$properties = $esmg->properties( $index, $type )

property

$property = $esmg->property( $index, $type, $propertyname )

documents

@documents = $esmg->documents(); # all documents for all indexes
@documents = $esmg->documents('cpan_v1'); # all documents for cpan_v1
@documents = $esmg->documents(''); # all documents for an index-free dataset.

ATTRIBUTES

mapping_url

rw, required

base_dir

rw, required

generator_base_class

rw, default: ElasticSearchX::Model::Generator

generated_base_class

rw, default: MyModel

document_generator_class

lazy

attribute_generator_class

lazy

typename_translator_class

lazy

document_generator

lazy

attribute_generator

lazy

typename_translator

lazy

PRIVATE ATTRIBUTES

_mapping_content

lazy

_ua

lazy

_mapping_data

lazy

PRIVATE METHODS

_build__ua

returns an HTTP::Tiny instance.

_build_document_generator_class

generator_base_class + '::DocumentGenerator'

_build_document_generator

returns an instance of $document_generator_class

_build_attribute_generator_class

generator_base_class + '::AttributeGenerator'

_build_attribute_generator

returns an instance of $attribute_generator_class

_build_typename_translator_class

generator_base_class + '::TypenameTranslator'

_build_typename_translator

returns an instance of $typename_translator_class

_build__mapping_content

returns the content of the URL at mapping_url

_build__mapping_data

returns the decoded data from JSON stored in _mapping_content

AUTHOR

Kent Fredric <kentfredric@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Kent Fredric <kentfredric@gmail.com>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.