@ApiOperation(value = "导入所有数据库中商品到ES") @RequestMapping(value = "/importAll", method = RequestMethod.POST) @ResponseBody public CommonResultimportAllList(){ int count = esProductService.importAll(); return CommonResult.success(count); }
importAll方法:
@Override publicintimportAll(){ List esProductList = productDao.getAllEsProductList(null); Iterable esProductIterable = productRepository.saveAll(esProductList); Iterator iterator = esProductIterable.iterator(); int result = 0; while (iterator.hasNext()) { result++; iterator.next(); } return result; }
<selectid="getAllEsProductList"resultMap="esProductListMap"> select p.id id, p.product_sn productSn, p.brand_id brandId, p.brand_name brandName, p.product_category_id productCategoryId, p.product_category_name productCategoryName, p.pic pic, p.name name, p.sub_title subTitle, p.price price, p.sale sale, p.new_status newStatus, p.recommand_status recommandStatus, p.stock stock, p.promotion_type promotionType, p.keywords keywords, p.sort sort, pav.id attr_id, pav.value attr_value, pav.product_attribute_id attr_product_attribute_id, pa.type attr_type, pa.name attr_name from pms_product p left join pms_product_attribute_value pav on p.id = pav.product_id left join pms_product_attribute pa on pav.product_attribute_id= pa.id where delete_status = 0 and publish_status = 1 <iftest="id!=null"> and p.id=#{id} if> select>
配置文件
# ======================== Elasticsearch Configuration ========================= # # NOTE: Elasticsearch comes with reasonable defaults for most settings. # Before you set out to tweak and tune the configuration, make sure you # understand what are you trying to accomplish and the consequences. # # es为大多数设置都给出了不错的默认值, 在你进行配置时, 确保你真的明白你这么做的影响以及结果. # # The primary way of configuring a node is via this file. This template lists # the most important settings you may want to configure for a production cluster. # Please consult the documentation for further information on configuration options: # https://www.elastic.co/guide/en/elasticsearch/reference/index.html # # 配置一个节点的主要方法之一就是通过这个文件, 这个模板罗列出了你可能想要配置集群的 # 最重要的设置项. # # ---------------------------------- Cluster ----------------------------------- # # Use a descriptive name for your cluster: 给你的集群设置一个集群名, 默认是elasticsearch # #cluster.name: my-application # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: 给你的节点设置节点名 # # 默认从elasticsearch-6.8.8.jar/lib/elasticsearch-6.8.8.jar!config/names.txt中随机选择一个名称 # #node.name: node-1 # # Add custom attributes to the node: 给你的节点设置一个标志(描述) # #node.attr.rack: r1 # # ----------------------------------- Paths ------------------------------------ # # Path to directory where to store the data (separate multiple locations by comma): # # 设置存储数据的目录的路径, 用逗号分隔多个位置, 默认存储在 es文件夹/data 目录下 # #path.data: /path/to/data # # Path to log files: 默认在es文件夹/logs # # 日志文件的路径 # #path.logs: /path/to/logs # # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: 锁定物理内存地址,防止elasticsearch内存被交换出去, # 也就是避免es使用swap交换分区 # #bootstrap.memory_lock: true # # Make sure that the heap size is set to about half the memory available # on the system and that the owner of the process is allowed to use this # limit. # # 确保将堆大小设置为可用内存的一半左右 # 在系统上,并且允许进程的所有者使用此 # 限制。 # # Elasticsearch performs poorly when the system is swapping the memory. # 当系统交换内存时,Elasticsearch的性能很差。 # ---------------------------------- Network ----------------------------------- # # Set the bind address to a specific IP (IPv4 or IPv6): # # 为es设置ip绑定,默认是127.0.0.1,也就是默认只能通过127.0.0.1 或者localhost才能访问 # # es1.x版本默认绑定的是0.0.0.0 所以不需要配置,但是es2.x版本默认绑定的是127.0.0.1,需要配置 # # network.host: 192.168.0.1 # # 生产环境, 这里换成0.0.0.0, 允许外部访问 network.host:0.0.0.0 # # # Set a custom port for HTTP: 为es设置自定义端口,默认是9200 # # 注意:在同一个服务器中启动多个es节点的话,默认监听的端口号会自动加1:例如:9200,9201,9202... # http.port: 9200 # # For more information, consult the network module documentation. 更多的信息在网络文档上 # # --------------------------------- Discovery ---------------------------------- # 当启动新节点时,通过这个ip列表进行节点发现,组建集群 # 默认节点列表: # 127.0.0.1,表示ipv4的回环地址。 # [::1],表示ipv6的回环地址 # # 在es1.x中默认使用的是组播(multicast)协议,默认会自动发现同一网段的es节点组建集群, # 在es2.x中默认使用的是单播(unicast)协议,想要组建集群的话就需要在这指定要发现的节点信息了。 # 注意:如果是发现其他服务器中的es服务,可以不指定端口[默认9300],如果是发现同一个服务器中的es服务,就需要指定端口了。 # # Pass an initial list of hosts to perform discovery when new node is started: # The default list of hosts is ["127.0.0.1", "[::1]"] # #discovery.zen.ping.unicast.hosts: ["host1", "host2"] # # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1): # 通过配置这个参数来防止集群脑裂现象 (集群总节点数量/2)+1 # #discovery.zen.minimum_master_nodes: (集群总节点数量/2)+1 # # For more information, consult the zen discovery module documentation. # # ---------------------------------- Gateway ----------------------------------- # # Block initial recovery after a full cluster restart until N nodes are started: # 一个集群中的N个节点启动后,才允许进行数据恢复处理,默认是1 # #gateway.recover_after_nodes: 3 # # For more information, consult the gateway module documentation. # # ---------------------------------- Various ----------------------------------- # 多样化配置: # # Require explicit names when deleting indices: 删除节点时需要明确的支出 # #action.destructive_requires_name: true # # #总结 # # 1、es已经为大多数参数设置合理的默认值 # # 2、这个配置文件中列出来了针对生产环境下的一些重要配置 # # 3、注意:这个文件是yaml格式的文件 # # (1):属性顶格写,不能有空格 # # (2):缩进一定不能使用tab制表符 # # (3):属性和值之间的:后面需要有空格 # network.host: 192.168.80.200 #
[2020-04-23T14:51:31,719][WARN ] [o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] uncaught exception in thread [main] org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
Caused by: java.lang.RuntimeException: can not run elasticsearch as root