简体   繁体   中英

How to create an index in Elasticsearch with an analyzer and shard defined?

I am trying to create an index with the mapping of text and keyword with the analyzer defined, here what i have tried till now:


{
    "settings" : {
        "number_of_shards" : 2,
        "number_of_replicas" : 1
    },

    "analysis": {
      "normalizer": {
        "my_normalizer": {
          "type": "custom",
          "char_filter": [],
          "filter": ["lowercase", "asciifolding"]
        }
      }
    }
  ,
    "mappings": {
    "properties": {
  "question": {
    "type":"text",
    "fields": {
      "keyword": {
        "type": "keyword"
      },
     "normalize": {
      "type": "keyword",
      "normalizer": "my_normalizer"
    }

}
}
}
}
}

I have tried this but getting error :

"error": {
    "root_cause": [
        {
            "type": "parse_exception",
            "reason": "unknown key [analysis] for create index"
        }
    ],
    "type": "parse_exception",
    "reason": "unknown key [analysis] for create index"
},
"status": 400

}

Question is the field where I need to add this mapping. I am trying this in AWS ES service.

Great start, you're almost there!

The analysis section needs to be located inside the top-level settings section, like this:

{
  "settings": {
    "index": {
      "number_of_shards": 2,
      "number_of_replicas": 1
    },
    "analysis": {
      "normalizer": {
        "my_normalizer": {
          "type": "custom",
          "char_filter": [],
          "filter": [
            "lowercase",
            "asciifolding"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "question": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          },
          "normalize": {
            "type": "keyword",
            "normalizer": "my_normalizer"
          }
        }
      },
      "answer": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          },
          "normalize": {
            "type": "keyword",
            "normalizer": "my_normalizer"
          }
        }
      }
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM