Symfony 如何正确配置FOS Elastica分析仪和过滤器?

Symfony 如何正确配置FOS Elastica分析仪和过滤器?,symfony,search,analyzer,elastica,foselasticabundle,Symfony,Search,Analyzer,Elastica,Foselasticabundle,在我的symfony2应用程序中,我使用FOS Elastica bundle执行搜索 我曾尝试设置分析器和过滤器,但它们似乎没有效果。例如,如果我搜索单词'cake',包含句子大小写'cake'的对象将不会返回 如何正确配置这些分析器和过滤器 我的配置: #Elastic Search fos_elastica: default_manager: orm clients: default: { host: localhost, port: 9200 }

在我的symfony2应用程序中,我使用FOS Elastica bundle执行搜索

我曾尝试设置分析器和过滤器,但它们似乎没有效果。例如,如果我搜索单词'cake',包含句子大小写'cake'的对象将不会返回

如何正确配置这些分析器和过滤器

我的配置:

#Elastic Search
fos_elastica:
    default_manager: orm
    clients:
        default: { host: localhost, port: 9200 }
    indexes:
        website:
            client: default
            settings:
                index:
                    analysis:
                        analyzer:
                            custom_index_analyzer :
                                type     :    custom
                                tokenizer:    nGram
                                filter   :    [stopwords, asciifolding ,lowercase, snowball, elision, worddelimiter]
                            custom_search_analyzer :
                                type     :    custom
                                tokenizer:    nGram
                                filter   :    [stopwords, asciifolding ,lowercase, snowball, elision, worddelimiter]
                        tokenizer:
                            nGram:
                                type:     nGram
                                min_gram: 1
                                max_gram: 2
                        filter:
                            snowball:
                                type:     snowball
                                language: French
                            elision:
                                type:     elision
                                articles: [l, m, t, qu, n, s, j, d]
                            stopwords:
                                type:      stop
                                stopwords: [_french_]
                                ignore_case : true
                            worddelimiter :
                                type:      word_delimiter
            index_name: foodmeup
            types:
                recipe:
                    mappings:
                        name:
                            boost: 5
                            index_analyzer : custom_index_analyzer
                            search_analyzer : custom_search_analyzer
                        nickName:
                            index_analyzer : custom_index_analyzer
                            search_analyzer : custom_search_analyzer
                        content:
                            index_analyzer : custom_index_analyzer
                            search_analyzer : custom_search_analyzer
                        recipeIngredients:
                            type: "nested"
                            properties:
                                name:
                                    index_analyzer : custom_index_analyzer
                                    search_analyzer : custom_search_analyzer
                                product:
                                    type: "nested"
                                    properties:
                                        name: { type: string, boost: 10}
                                        nickName: { type: string }
                                        content: { type: string }
                                        tags:
                                            type: "nested"
                                            boost: 5
                                            properties:
                                                name: { type: string }
                        userRecipes:
                            type: "nested"
                            properties:
                                name:
                                    index_analyzer : custom_index_analyzer
                                    search_analyzer : custom_search_analyzer
                                content:
                                    index_analyzer : custom_index_analyzer
                                    search_analyzer : custom_search_analyzer
                        tags:
                            type: "nested"
                            boost: 5
                            properties:
                                name:
                                    index_analyzer : custom_index_analyzer
                                    search_analyzer : custom_search_analyzer
                    persistence:
                        driver: orm
                        model: AppBundle\Entity\FoodAnalytics\Recipe
                        repository: AppBundle\Repository\FoodAnalytics\RecipeRepository
                        provider: ~
                        finder: ~
                        listener: ~ # by default, listens to "insert", "update" and "delete"
                product:
                    mappings:
                        name: { type: string, boost: 10}
                        nickName: { type: string }
                        content: { type: string }
                        userIngredients:
                            type: "nested"
                            properties:
                                name: { type: string }
                                content: { type: string }
                        tags:
                            type: "nested"
                            boost: 5
                            properties:
                                name: { type: string }
                    persistence:
                        driver: orm
                        model: AppBundle\Entity\MarketPlace\Product
                        repository: AppBundle\Repository\MarketPlace\ProductRepository
                        provider: ~
                        finder: ~
                        listener: ~ # by default, listens to "insert", "update" and "delete"
                user:
                    mappings:
                        firstName: { type: string, boost: 3}
                        lastName: { type: string, boost: 10 }
                        content: { type: string }
                        username: { type: string }
                        email: { type: string }
                        jobSeeker:
                            type: "nested"
                            properties:
                                skills:
                                    type: "nested"
                                    properties:
                                        name: { type: string }
                                experiences:
                                    type: "nested"
                                    properties:
                                        position:
                                            type: "nested"
                                            properties:
                                                name: { type: string }
                                        content: { type: string }
                                trainings:
                                    type: "nested"
                                    properties:
                                        name: { type: string }
                                        content: { type: string }
                                        diploma:
                                            type: "nested"
                                            properties:
                                                name: { type: string }
                    persistence:
                        driver: orm
                        model: AppBundle\Entity\User\User
                        repository: AppBundle\Repository\User\UserRepository
                        provider: ~
                        finder: ~
                        listener: ~ # by default, listens to "insert", "update" and "delete"
                organization:
                    mappings:
                        name: { type: string, boost: 10}
                        legalName: { type: string, boost: 10}
                        shortDescription: { type: string, boost: 3}
                        route: { type: string}
                        content: { type: string }
                    persistence:
                        driver: orm
                        model: AppBundle\Entity\User\Organization
                        repository: AppBundle\Repository\User\OrganizationRepository
                        provider: ~
                        finder: ~
                        listener: ~ # by default, listens to "insert", "update" and "delete"
                offer:
                    mappings:
                        name: { type: string, boost: 10}
                        content: { type: string }
                        responsibilities: { type: string }
                        skills:
                            type: "nested"
                            properties:
                                name: { type: string }
                        contractType:
                            type: "nested"
                            properties:
                                name: { type: string }
                        position:
                            type: "nested"
                            properties:
                                name: { type: string, boost: 10 }
                    persistence:
                        driver: orm
                        model: AppBundle\Entity\Job\Offer
                        repository: AppBundle\Repository\Job\OfferRepository
                        provider: ~
                        finder: ~
                        listener: ~
                post:
                    mappings:
                        name: { type: string, boost: 10}
                        content: { type: string }
                        summary: { type: string }
                        tags:
                            type: "nested"
                            boost: 5
                            properties:
                                name: { type: string }
                        comments:
                            type: "nested"
                            properties:
                                content: { type: string }
                    persistence:
                        driver: orm
                        model: AppBundle\Entity\Social\Post
                        repository: AppBundle\Repository\Social\PostRepository
                        provider: ~
                        finder: ~
                        listener: ~
该查询是一个基本查询:

$finder = $this->container->get('website.recipe')
$elasticaResults = $finder->find($search);

每次更新
fos_elastica
config
文件时,您需要在第一时间使用以下命令更新索引:

php app/console fos:elastica:populate --index website --type= <<you type>>
php应用程序/控制台fos:elastica:populate——索引网站——类型=
此命令将通过删除上一个数据来重新索引数据。第二次,您应该检查您的映射信息,以检查一切是否正常和同步

您可以使用以下命令检查分析仪:

curl 'http://<< yourdomain >>:9200/website/_analyze?pretty=true&analyzer=custom_french_analyzer' -d "Cake"
curl'http://>:9200/website/\u analyze?pretty=true&analyzer=custom\u french\u analyzer'-d“蛋糕”

如果没有查询,我们如何帮助您……嗯,查询工作正常,这是需要一些设置的配置。我已经添加了查询,以防它更改某些内容,但我不这么认为。。。还是我弄错了?乍一看,您的配置文件似乎很好(至少对我来说是这样)。我有几个问题:-你有没有用任何类型的数据填充索引?php应用程序/控制台f:e:p--index=website-您是否使用测试工具测试了您的查询?我在这篇评论中移动了我的“答案”。请检查elasticsearch中的映射是否正确:GET/website/\u mapping尝试将小写筛选器放在第一个位置。