FriendsOfSymfony / FOSElasticaBundle

Elasticsearch PHP integration for your Symfony project using Elastica.
http://friendsofsymfony.github.io
MIT License
1.25k stars 793 forks source link

How to set multi_field in config.yml? #495

Closed ushios closed 10 years ago

ushios commented 10 years ago
fos_elastica:
    clients:
        default: { host: "xxx.xxx.com", port: 9200 }
    indexes:
        reporters:
            client: default
            index_name: reporters
            settings:
                index:
                    analysis:
                        analyzer:
                            my_kuromoji:
                                type: kuromoji
                                mode: search
                                tokenizer: kuromoji_tokenizer
            types:
                models:
                    mappings:
                        self_pr:
                            type: string
                            analyzer: my_kuromoji
                        nickname_ja:
                            type: string
                            index: analyzed
                            analyzer: my_kuromoji
                            fields:
                                full:
                                    type: string
                                    index: not_analyzed
                        brithday:
                            type: date
                        height:
                            type: integer
                        bast:
                            type: integer
                        hip:
                            type: integer
                        waist:
                            type: integer

Command app/console fos:elastica:reset has error.

[Elastica\Exception\ResponseException]
RemoteTransportException[[Machine Man][inet[/xx.xx.xx.xx:9300]][indices/create]]; nested: MapperParsingException[mapping [models]]; nested: ClassCastException[java.util.ArrayList cannot be cast to java.util.Map]; 

I was tested on elastica-bundle 3.0.*@dev, elasticsearch 1.0.0RC1 and 1.0.1 but faild both version.

ushios commented 10 years ago
        nickname_ja:
            type: multi_field
            analyzer: my_kuromoji
            fields:
                nickname_ja:
                    type: string
                    index: analyzed
                    analyzer: my_kuromoji
                full:
                    type: string
                    index: not_analyzed

Using type:multi_filed but faild too.

npinon commented 10 years ago

:+1: same here. I have defined the fields and populate the config:

                    mappings:
                        title:
                            type: string
                            fields:
                                raw:
                                    type: string
                                    index: not_analyzed

But when I get the mapping from elasticsearch :

          "title" : {
            "type" : "string"
          },

There is no fields section...

Can someone help us?

npinon commented 10 years ago

Temporary solution

I have pushed manually the modified mapping :

curl -XPUT 'http://localhost:9200/xxx/xxx/_mapping' -d '{
  "xxx":{
    "properties": {
      "title": {
        "type": "string",
        "fields": {
          "raw": {
            "type": "string",
            "index": "not_analyzed"
          },
          "first_letter": {
            "type": "string",
            "analyzer": "first_letter"
          },
          "analysed": {
            "type": "string",
            "analyzer": "custom_search_analyzer"
          }
        }
      },
    }
}'

Then re-populate without resetting index :

php app/console fos:elastica:populate --no-reset

And it works. But it's annoying...