ElasticSearch 7.x 默认不在支持指定索引类型

原文: ElasticSearch 7.x 默认不在支持指定索引类型

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/u014646662/article/details/94718834

ElasticSearch 7.x 默认不在支持指定索引类型

在elasticsearch7.x上执行:
 


   
   
  1. put es_test
  2. {
  3. "settings":{
  4. "number_of_shards" : 3,
  5. "number_of_replicas" : 0
  6. },
  7. "mappings":{
  8. "books":{
  9. "properties":{
  10. "title":{ "type": "text"},
  11. "name":{ "type": "text", "index": false},
  12. "publish_date":{ "type": "date", "index": false},
  13. "price":{ "type": "double"},
  14. "number":{
  15. "type": "object",
  16. "dynamic": true
  17. }
  18. }
  19. }
  20. }
  21. }

执行结果则会出错:Root mapping definition has unsupported parameters


   
   
  1. {
  2. "error": {
  3. "root_cause": [
  4. {
  5. "type": "mapper_parsing_exception",
  6. "reason": "Root mapping definition has unsupported parameters: [books : {properties={number={dynamic=true, type=object}, price={type=double}, name={index=false, type=text}, title={type=text}, publish_date={index=false, type=date}}}]"
  7. }
  8. ],
  9. "type": "mapper_parsing_exception",
  10. "reason": "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [books : {properties={number={dynamic=true, type=object}, price={type=double}, name={index=false, type=text}, title={type=text}, publish_date={index=false, type=date}}}]",
  11. "caused_by": {
  12. "type": "mapper_parsing_exception",
  13. "reason": "Root mapping definition has unsupported parameters: [books : {properties={number={dynamic=true, type=object}, price={type=double}, name={index=false, type=text}, title={type=text}, publish_date={index=false, type=date}}}]"
  14. }
  15. },
  16. "status": 400
  17. }

如果在6.x上执行,则会正常执行


   
   
  1. {
  2. "acknowledged" : true
  3. }

出现这个的原因是,elasticsearch7默认不在支持指定索引类型,默认索引类型是_doc,如果想改变,则配置include_type_name: true 即可(这个没有测试,官方文档说的,无论是否可行,建议不要这么做,因为elasticsearch8后就不在提供该字段)。官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html

所以在Elasticsearch7中应该这么创建索引


   
   
  1. put / test
  2. {
  3. "settings":{
  4. "number_of_shards":3,
  5. "number_of_replicas":2
  6. },
  7. "mappings":{
  8. "properties":{
  9. "id":{ "type": "long"},
  10. "name":{ "type": "text", "analyzer": "ik_smart"},
  11. "text":{ "type": "text", "analyzer": "ik_max_word"}
  12. }
  13. }
  14. }
  15. put /test1
  16. {
  17. "settings":{
  18. "number_of_shards":3,
  19. "number_of_replicas":2
  20. },
  21. "mappings":{
  22. "properties":{
  23. "id":{ "type": "long"},
  24. "name":{ "type": "text"},
  25. "text":{ "type": "text"}
  26. }
  27. }
  28. }

对人工智能感兴趣的同学,可以点击以下链接:

现在人工智能非常火爆,很多朋友都想学,但是一般的教程都是为博硕生准备的,太难看懂了。最近发现了一个非常适合小白入门的教程,不仅通俗易懂而且还很风趣幽默。所以忍不住分享一下给大家。点这里可以跳转到教程。

https://www.cbedai.net/u014646662

猜你喜欢

转载自www.cnblogs.com/lonelyxmas/p/11612940.html