ElasticSearch mapping and index properties.

Using Elastica i could do something like:




$elasticaIndex->create(array(

        'number_of_shards' => 4,

        'number_of_replicas' => 1,

        'analysis' => array(

            'analyzer' => array(

                'indexAnalyzer' => array(

                    'type'		=> 'custom',

                    'tokenizer' => 'standard',

                ),

                'searchAnalyzer' => array(

                    'type'		=> 'custom',

                    'tokenizer' => 'standard',

                ),

                'stringLowercase' => array(

                	'type'		=> 'custom',

					'tokenizer' => 'keyword',

        			'filter' 	=> 'lowercase'

				),

				'autocomplete' => array(

					'type' => 'custom',

					'tokenizer' => 'standard',

					'filter' => array('standard', 'lowercase', 'stop', 'kstem', 'myNgram'),

				),  

            ),

            'filter' => array(

            	'myNgram' => array(

					'type' => 'ngram',

		            'min_gram' => 3,

		            'max_gram' => 15

	            ),

			),

        )

    ),

    true

);


$mapping = new \Elastica\Type\Mapping();

$mapping->setType($elasticaType);

$mapping->setParam('index_analyzer', 'indexAnalyzer');

$mapping->setParam('search_analyzer', 'searchAnalyzer');

$mapping->setProperties(array(

	'search_type_id'	=> array(

		'type' 				=> 'integer', 

		'include_in_all' 	=> false

	),

	'search_name'	=> array(

		'type' 				=> 'string', 

		'include_in_all' 	=> false,

		'analyzer'			=> 'stringLowercase',

	),

);



How can i achieve this with Yii’s implementation?

Just for the others to know and not waste the time with this since it brought me only frustration.

The current yii implementation, as far as i saw, is very limited, if you want to store simple data, then it’s fine, but when you need to create mappings with analyzers and such, then you need a library like Elastica.

After you index your data with Elastica (because you can’t do it with yii), you can use yii’s implementation to retrieve basic data, but at the time when you need to build complex queries with filters and such, then again, you need to get back to Elastica.

Yii provides a query() and filter() method, but it’s very inefficient to work with them (as opposed to Elastica’s classes which just make sense when used), it makes you think that it’s something started but not finished.

Too bad, but gladly we have alternatives.

Thanks :)

Want to make clear.

What’s “$elasticaIndex” in your code? I did not see your code using that.

Elastica is a PHP client for ElasticSearch, did you compared Elastica with ElasticSearch original PHP client? Which one is better or easier to use?

Thank you very much!