Search code examples
symfonyelasticsearchyamlfoselasticabundle

Unrecognized option "types" | FOS Elastica & Symfony


I am able to create indexes 1 by 1 but my purpose is to have 1 big index with subindexes to search. (I am reproducing an existing app but upgrading dependencies)

Symfony : 5.4* FOS-Elastica : 6.1 Elastic : 7*

This is my error message and if I change types to properties I have similar errors. I have been trying to switch and indent differently all day:

Unrecognized option "types" under "fos_elastica.indexes.app". Available options are "_id", "_routing", "_source", "analyzer", "client", "date_detection", "dynamic", "dynamic_date_formats", "dynamic_templates", "finder", "index_   
  name", "index_prototype", "indexable_callback", "numeric_detection", "persistence", "properties", "serializer", "settings", "use_alias".   

What am I doing wrong please ?

#app/config/config.yml
fos_elastica:
    clients:
        default: { host: localhost, port: 9200 }

    indexes:
        app:
            settings:
                analysis:
                    analyzer:
                        fr:
                            tokenizer: standard
                            filter: [ lowercase, stop_fr, snowball_fr ]
                        autocomplete:
                            type: custom
                            tokenizer: whitespace
                            filter: [ lowercase, engram, elision ]
                        csv:
                            type: pattern
                            pattern: '\s*,\s*'
                            lowercase: false
                    filter:
                        snowball_fr:
                            type: "snowball"
                            language: "French"
                        stop_fr:
                            type: "stop"
                            stopwords: "_french_"
                        engram:
                            type: edge_ngram
                            min_gram: 2
                            max_gram: 15
            types:
                # ---------
                # USER
                # ---------
                user:
                    properties:
                        username: ~
                        email: ~
                        organization:
                            type: object
                            properties:
                                id: { index: true }
                                code: { index: true }
                                name:
                                    index: true
                                    type: text
                                    fields:
                                        source: { type: text, index: true }
                    persistence:
                        driver: orm # orm, mongodb, propel are available
                        model: App\Entity\User
                        provider: ~
                        listener: ~
                        finder: ~

Solution

  • So I was also figuring out how to deal with the same issue as yours, and I do confirm lot of the docs and blogposts out there use the config struture you posted. However when I went back to the v6.1 documentation of the bundle I found this:

    Dynamic templates

    Dynamic templates allow to define mapping templates that will be applied when dynamic introduction of fields / objects happens.

    Documentation

    fos_elastica:
        indexes:
            user:
                dynamic_templates:
                    my_template_1:
                        match: apples_*
                        mapping:
                            type: float
                    my_template_2:
                        match: *
                        match_mapping_type: text
                        mapping:
                            type: keyword
                properties:
                    username: { type: text }
    

    So in your case a working config would look like:

    #app/config/config.yml
    fos_elastica:
      clients:
        default: { host: localhost, port: 9200 }
    
      indexes:
        user:
          settings:
            analysis:
              analyzer:
                fr:
                  tokenizer: standard
                  filter: [ lowercase, stop_fr, snowball_fr ]
                autocomplete:
                  type: custom
                  tokenizer: whitespace
                  filter: [ lowercase, engram, elision ]
                csv:
                  type: pattern
                  pattern: '\s*,\s*'
                  lowercase: false
              filter:
                snowball_fr:
                  type: "snowball"
                  language: "French"
                stop_fr:
                  type: "stop"
                  stopwords: "_french_"
                engram:
                  type: edge_ngram
                  min_gram: 2
                  max_gram: 15
          properties:
            username: ~
            email: ~
            organization:
              type: object
              properties:
                id: { index: true }
                code: { index: true }
                name:
                  index: true
                  type: text
                  fields:
                    source: { type: text, index: true }
          persistence:
            driver: orm # orm, mongodb, propel are available
            model: App\Entity\User
            provider: ~
            listener: ~
            finder: ~