Elasticquent icon indicating copy to clipboard operation
Elasticquent copied to clipboard

search in nested and partial words

Open maganius opened this issue 7 years ago • 1 comments

How I can search in a nested? and how I can search with partial words? its my mapping:

protected $mappingProperties = array(
        'id' => array('type' => 'integer', 'index' => false),
        'nombre' => array('type' => 'text', 'analyzer' => 'spanish_search_analyzer', 'index' => true),
        'slug' => array('type' => 'text', 'analyzer' => 'spanish_index_analyzer', 'index' => true),
        'created_at' => array('type' => 'date', 'format'=> 'yyyy-MM-dd HH:mm:ss', 'index' => false),
        'updated_at' => array('type' => 'date', 'format'=> 'yyyy-MM-dd HH:mm:ss', 'index' => false),
        'institucion' => array('type' => 'nested', 'properties' => array(
            'id' => array('type' => 'integer', 'index' => false),
            'nombre' => array('type' => 'text', 'index' => true, 'analyzer' => 'spanish_index_analyzer'),
        )),
        'comuna' => array('type' => 'nested', 'index' => true, 'properties' => array(
            'id' => array('type' => 'integer', 'index' => false),
            'ciudad_id' => array('type' => 'integer', 'index' => false),
            'nombre' => array('type' => 'text', 'index' => true, 'analyzer' => 'spanish_search_analyzer'),
            'region' => array('type' => 'nested', 'properties' => array(
                'id' => array('type' => 'integer', 'index' => false),
                'nombre' => array('type' => 'text', 'index' => true, 'analyzer' => 'spanish_search_analyzer'),
            ))
        )),
    );

I need search in nombre and comuna.nombre field, my query is working only in nombre field but it have the problem I need write a whole word to found results, I can't write parcial words. The another problem is the comuna.nombre nested field I can't get my query to search there, anyone can help me? its my basic query to nombre field and work writing the whole word.

array (
            'bool' => array (
                'should' => array (
                    array (
                        'match' => array ('nombre' => 'producers') // with 'produc' it dint work
                    ),
                ),
            ),
        )

its my query to work with nested but it dint work

array ('bool' =>
            array ('should' =>
                array (
                    array ('match' => array ('nombre' => 'producers')),
                    array ('bool' =>
                        array ('should' =>
                            array (
                                array ('nested' =>
                                    array (
                                        'path' => 'comuna',
                                        'query' =>
                                            array ('match' => array ('comuna.nombre' => 'Comuna 1'),
                                            ),
                                    ),
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        )
{
	"bool": {
		"should": [{
				"match": {
					"nombre": "producers"
				}
			}, {
				"bool": {
					"should": [{
							"nested": {
								"path": "comuna",
								"query": {
									"match": {
										"comuna.nombre": "Comuna 1"
									}
								}
							}
						}
					]
				}
			}
		]
	}
}

maganius avatar Dec 23 '18 20:12 maganius

I'm also facing problem of getting empty result when trying to search "prod" instead of "producers".

Anyone has solution for that?

PinalPatel160 avatar Sep 29 '21 18:09 PinalPatel160