4

when i first create index and then add type with mapping it all work. but when i try to create an index with mappings in one call, i get error:

"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [my_type]: Expected map for property [fields] on field [type] but got a class java.lang.String",

how to fix it? my code below:

create:

PUT /my_index
{
    "settings": {
        "number_of_shards": 1,  
        "analysis": {
            "filter": {
                "my_shingle_filter": {
                    "type":             "shingle",
                    "min_shingle_size": 2, 
                    "max_shingle_size": 3, 
                    "output_unigrams":  false,   
                    "filler_token": ""
                },
                "kill_fillers": {
                    "type": "pattern_replace",
                    "pattern": ".*_.*",
                    "replace": ""
                }
            },
            "analyzer": {
                "my_shingle_analyzer": {
                    "type":             "custom",
                    "tokenizer":        "standard",
                    "filter": [
                        "standard"
                        ,"lowercase"
                        ,"stop"
                        ,"porter_stem"
                        ,"my_shingle_filter" 
                        ,"trim"
                    ]
                }}}}}

add type:

PUT /my_index/_mapping/my_type
{
    "my_type": {
        "properties": {
            "title": {
                "type": "string",
                "fields": {
                    "shingles": {
                        "type":     "string",
                        "analyzer": "my_shingle_analyzer"
                    }}}}}}

create index together with mapping:

PUT /my_index
{
  "settings": {
    "number_of_shards": 1,
    "analysis": {
      "filter": {
        "my_shingle_filter": {
          "type": "shingle",
          "min_shingle_size": 2,
          "max_shingle_size": 2,
          "output_unigrams": false
        }
      },
      "analyzer": {
        "my_shingle_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "my_shingle_filter"
          ]
        }}}
  },
  "mappings": {
    "my_type": {
      "properties": {
        "type": "string",
        "fields": {
          "shingles": {
            "type": "string",
            "analyzer": "my_shingle_analyzer"
          }}}}}}

1 Answer 1

4

You're simply missing the title field in your second query:

PUT /my_index
{
  "settings": {
    "number_of_shards": 1,
    "analysis": {
      "filter": {
        "my_shingle_filter": {
          "type": "shingle",
          "min_shingle_size": 2,
          "max_shingle_size": 2,
          "output_unigrams": false
        }
      },
      "analyzer": {
        "my_shingle_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "my_shingle_filter"
          ]
        }}}
  },
  "mappings": {
    "my_type": {
      "properties": {
       "title": {                    <--- this line is missing
        "type": "string",
        "fields": {
          "shingles": {
            "type": "string",
            "analyzer": "my_shingle_analyzer"
          }}}}}}}                    <--- + one closing brace
Sign up to request clarification or add additional context in comments.

1 Comment

Always glad to help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.