Skip to content

Instantly share code, notes, and snippets.

@ahmed-bhs
Created October 10, 2018 15:15
Show Gist options
  • Save ahmed-bhs/e04e4771695368648253412c48f24b27 to your computer and use it in GitHub Desktop.
Save ahmed-bhs/e04e4771695368648253412c48f24b27 to your computer and use it in GitHub Desktop.

Using fos_elastica.finder.post_index.post service to get list of sugesstion available from my mapping:


fos_elastica:
    clients:
        default: { host: elasticsearch, port: 9200 }
    indexes:
        post_index:
            client: default
            index_name: post_index
            types:
                post:
                    properties:
                        suggest:
                            type: completion
                        id:
                            type: keyword
                        title:
                            type: keyword
                        description:
                            type: keyword

                    persistence:
                        driver: orm
                        model: App\Entity\Post
                        finder: ~
                        provider: ~
                        listener: ~

This is my php code under SearchController:


        $finder = $this->container->get('fos_elastica.finder.post_index.post');

        $compelation = [
                "suggest" => [
                    "suggest" => [
                        "text" => "test",
                        "completion" => [
                            "field" => "suggest",
                            "fuzzy" => ["fuzziness" => 2]
                        ],
                    ]
                ]
            ];

        $result = $finder->find($compelation);

The post request work great under kibana console and return the appropriate result:


POST post_index/_search?pretty
{
    "suggest": {
        "anything-suggest" : {
            "text" : "test",
            "completion" : {
                "field" : "suggest",
                "fuzzy" : {
                    "fuzziness" : 2
                }
            }
        }
    }
}

This is the error I'm getting:

suggestion does not support [field]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment