2013-10-07 26 views
8

我正在學習elasticsearch。我已經在'mapping.json'中指定了映射。其內容有curl -X POST -d @ mapping.json +未創建映射

{ 
    "book" : { 
     "_index" : { 
      "enabled" : true 
     }, 
     "_id" : { 
      "index": "not_analyzed", 
      "store" : "yes" 
     }, 
     "properties" : { 
      "author" : { 
       "type" : "string" 
      }, 
      "characters" : { 
       "type" : "string" 
      }, 
      "copies" : { 
       "type" : "long", 
       "ignore_malformed" : false 
      }, 
      "otitle" : { 
       "type" : "string" 
      }, 
      "tags" : { 
       "type" : "string" 
      }, 
      "title" : { 
       "type" : "string" 
      }, 
      "year" : { 
       "type" : "long", 
       "ignore_malformed" : false, 
       "index" : "analyzed" 
      }, 
      "available" : { 
       "type" : "boolean", 
       "index" : "analyzed" 
      } 
     } 
    } 
} 

本映射是

$ curl -XGET http://localhost:9200/_mapping?pretty 
=> { 
    "development_users" : { 
     "user" : { 
     "properties" : { 
      "email" : { 
       "type" : "string" 
      }, 
      "first_name" : { 
       "type" : "string" 
      }, 
      "id" : { 
       "type" : "string", 
       "index" : "not_analyzed", 
       "omit_norms" : true, 
       "index_options" : "docs", 
       "include_in_all" : false 
      }, 
      "last_name" : { 
       "type" : "string" 
      }, 
      "role" : { 
       "type" : "string" 
      } 
     } 
    } 
    } 
} 

我使用命令創建書籍映射

$ curl http://localhost:9200/books -X POST -d @mapping.json 
=> {"ok":true,"acknowledged":true} 

但是,當列表中的所有映射,我得到:

$ curl -XGET http://localhost:9200/_mapping?pretty 
=> { "books" : { }, 
    "development_users" : { 
     "user" : { 
     "properties" : { 
      "email" : { 
       "type" : "string" 
      }, 
      "first_name" : { 
       "type" : "string" 
      }, 
      "id" : { 
       "type" : "string", 
       "index" : "not_analyzed", 
       "omit_norms" : true, 
       "index_options" : "docs", 
       "include_in_all" : false 
      }, 
      "last_name" : { 
       "type" : "string" 
      }, 
      "role" : { 
       "type" : "string" 
      } 
     } 
     } 
    } 
} 

爲什麼不是映射如何根據mapping.json文件中的指定創建書籍?

+0

沒有任何的旨意答案的解決這一問題? – spuder

回答

11

請試試這個,

curl -XPUT 'http://localhost:9200/<indexname>/book/_mapping' -d @mapping.json 
3

命令

curl -XPUT localhost:9200/_template/logstash -d @/Users/template.json 

響應

{"acknowledged":true} 
0

在AWS上我得到了一個錯誤,如

{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406} 

要解決它,我加入

-H 'Content-Type: application/json'