Symfony2 ElasticSearch sort mapping errors
<p>I am trying to sort the poducts by price using elastic.. However for some reason the field is not mapped and I get an error. I dont exactly know what im doing, sine this is the first time im using something like this.. Help woould be great!</p>

<p>In my products entity I have a simple field called base that stores the prices:</p>

<pre><code>/**
 * @ORM\Column(name="base", type="decimal", precision=10, scale=2, nullable=true)
 */
private $base;
</code></pre>

<p>My config.yml:</p>

<pre><code>fos_elastica:
    default_manager: orm
    clients:
        default: { host: localhost, port: 9200 }
    indexes:
        app:
            index_name: app_%kernel.environment%
            types:
                product:
                    mappings:
                        id:
                            type: integer
                        adminTitle:
                            type: string
                        base:
                            type: double
                    persistence:
                        # the driver can be orm, mongodb, phpcr or propel
                        # listener and finder are not supported by
                        # propel and should be removed
                        driver: orm
                        model: Mp\ShopBundle\Entity\Product
                        provider: ~
                        listener:
                            immediate: ~
                        finder: ~
                        repository: Mp\ShopBundle\Repository\ProductRepository
                        elastica_to_model_transformer:
                            query_builder_method: findProductsBySearch
                            ignore_missing: true
</code></pre>

<p>So to get products I am using my own function:</p>

<pre><code>    public function findProductsBySearch($data)
    {

        $qb = $this-&gt;createQueryBuilder('o');
        $qb-&gt;addSelect('trans')-&gt;join('o.translations', 'trans');
        $qb-&gt;addSelect('gallery')-&gt;join('o.gallery', 'gallery');
        $qb-&gt;addSelect('media')-&gt;join('gallery.galleryHasMedias', 'media');
        $qb-&gt;addSelect('image')-&gt;join('media.media', 'image');
        $qb-&gt;where("LOWER(o.adminTitle) LIKE :name");
        $qb-&gt;SetParameter('name', '%'.strtolower($data).'%');
//
//        var_dump($qb);
//        die;

        return $qb;
//        return $qb-&gt;getQuery();

    }
</code></pre>

<p>PROBLEM:</p>

<p>When I try to sort the products found I am getting an error:</p>

<pre><code>Parse Failure [No mapping found for [o.base] in order to sort on]
</code></pre>

<p>If to my query I add :</p>

<pre><code>$qb-&gt;addSelect('o.base');
</code></pre>

<p>I get:</p>

<pre><code>Cannot read property "id" from an array. Maybe you intended to write the property path as "[id]" instead.
</code></pre>

<p>Now Im stuck both ways..</p>

<p>P.S</p>

<p>I am sorting with knp paginator in my twig:</p>

<pre><code>&lt;ul class="dropdown-menu"&gt;
   &lt;li&gt;{{  knp_pagination_sortable(pagination, 'Más barato', 'o.base', {'direction': 'desc'}) }}&lt;/li&gt;
   &lt;li&gt;{{ knp_pagination_sortable(pagination, 'Más caro', 'o.base', {'direction': 'asc'}) }}&lt;/li&gt;
   &lt;li&gt;{{ knp_pagination_sortable(pagination, 'Más nuevo', 'o.created_at', {'direction': 'desc'}) }}&lt;/li&gt;
   &lt;li&gt;{{ knp_pagination_sortable(pagination, 'Más antiguo', 'o.created_at', {'direction': 'asc'}) }}&lt;/li&gt;
&lt;/ul&gt;
</code></pre>