为弹性搜索索引创建映射时出现 MapperParsingException

MapperParsingException when creating mapping for elasticsearch index

我正在尝试使用 sense 为具有三个属性的索引创建映射。当我尝试创建它时,我得到以下响应

{
   "error": "MapperParsingException[Root type mapping not empty after parsing! Remaining fields:   [mappings : {gram={properties={gram={type=string, fields={gram_bm25={type=string, similarity=BM25}, gram_lmd={type=string}}}, sentiment={type=string, index=not_analyzed}, word={type=string, index=not_analyzed}}}}]]",
   "status": 400
}

这是我在sense console里的

PUT /pos/_mapping/gram
{
  "mappings": {
    "gram": {
      "properties": {
        "gram": {
          "type": "string",
          "fields": {
            "gram_bm25": {
              "type": "string", "similarity": "BM25"
            },
            "gram_lmd": {
              "type": "string"
            }
          }
        },
        "sentiment": {
          "type": "string", "index": "not_analyzed"
        },
        "word": {
          "type": "string", "index": "not_analyzed"
        }
      }
    }
  }
}

谢谢!

您只是 API 语法错误。基本上,您结合了两种不同的方法。

创建索引,然后应用映射:

DELETE /pos

PUT /pos

PUT /pos/gram/_mapping
{
   "gram": {
      "properties": {
         "gram": {
            "type": "string",
            "fields": {
               "gram_bm25": {
                  "type": "string",
                  "similarity": "BM25"
               },
               "gram_lmd": {
                  "type": "string"
               }
            }
         },
         "sentiment": {
            "type": "string",
            "index": "not_analyzed"
         },
         "word": {
            "type": "string",
            "index": "not_analyzed"
         }
      }
   }
}

或者在创建索引时一次性完成:

DELETE /pos

PUT /pos
{
   "mappings": {
      "gram": {
         "properties": {
            "gram": {
               "type": "string",
               "fields": {
                  "gram_bm25": {
                     "type": "string",
                     "similarity": "BM25"
                  },
                  "gram_lmd": {
                     "type": "string"
                  }
               }
            },
            "sentiment": {
               "type": "string",
               "index": "not_analyzed"
            },
            "word": {
               "type": "string",
               "index": "not_analyzed"
            }
         }
      }
   }
}

这是我使用的代码:

http://sense.qbox.io/gist/6d645cc069f5f0fcf14f497809f7f79aff7de161