K
K
Konstantin2015-05-21 22:39:06
elasticsearch
Konstantin, 2015-05-21 22:39:06

Why does ElasticSearch only search for 4 characters or more when querying?

Why does ElasticSearch only search for 4 characters or more when querying? Can this be configured somehow?
mapping:

$property_us = array(
            'id' => array('type' => 'integer', 'include_in_all' => FALSE),
            'user' => array(
                'type' => 'object',
                'properties' => array(
                    'name' => array('type' => 'string',  'analyzer'=> $this->indexes_types['user']['type'], 'include_in_all' => TRUE),
                    'second_name' => array('type' => 'string', 'analyzer'=> $this->indexes_types['user']['type'], 'include_in_all' => TRUE),
                    'id' => array('type' => 'integer', 'include_in_all' => TRUE)
                ),
            ),
            'location' => array(
                'type' => 'object',
                'properties' => array(
                    'country' => array('type' => 'string', 'include_in_all' => TRUE),
                    'city' => array('type' => 'string', 'include_in_all' => TRUE)
                ),
            ),
            '_boost' => array('type' => 'float', 'include_in_all' => FALSE)
        );

index:
$this->elasticaIndex->create(array(
            'number_of_shards' => 1,
            'number_of_replicas' => 1,
            'analysis' => array(
                'analyzer' => array(
                    $type.'Analyzer' => array(
                        'type' => 'custom',
                        'tokenizer' => 'standard',
                        'filter' => array('lowercase', 'asciifolding', 'mySnowball')
                    ),
                    $type.'Analyzer' => array(
                        'type' => 'custom',
                        'tokenizer' => 'standard',
                        'filter' => array('standard', 'lowercase', 'asciifolding', 'mySnowball')
                    )
                ),
                'filter' => array(
                    'mySnowball' => array(
                        'type' => 'nGram',
                        'min_gram' => 1,
                        'max_gram' => 20
                    )
                )
            )
        ), true);

The request itself:
public function Query($value)
    {
        $elasticaQueryString = new \Elastica\Query\QueryString();
        $elasticaQueryString->setQuery((string)$value);

        // Create the actual search object with some data.
        $elasticaQuery = new \Elastica\Query();
        $elasticaQuery->setQuery($elasticaQueryString);

        //Search
        $search = new \Elastica\Search($this->elastic);
        $search->addIndex('users');
       
        //Options
        $elasticaQuery->setSort(array("name" => "asc"))
        ->setFrom(0)
        ->setLimit(25);

        $this->elasticaResults = $search->search($elasticaQuery);
        $this->elasticCount = $search->count($elasticaQuery);

    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question