一个关于spring-data-elasticSearch的问题

首先呢,我设置了一个model

@Data
@Document(indexName = "myes2", type = "tt")
public class MyEs2 implements Serializable {

    @Id
    @Field(type = FieldType.Long, store = true, index = false)
    private Long id;

    @Field(type = FieldType.Text, store = true, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String title;

    @Field(type = FieldType.Text, store = true, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String content;
}

可以看到ID我设置的是long类型,但是呢生成的mapping就变成了keyword

{
    "myes2": {
        "mappings": {
            "tt": {
                "properties": {
                    "content": {
                        "type": "text",
                        "store": true,
                        "analyzer": "ik_max_word",
                        "search_analyzer": "ik_smart"
                    },
                    "id": {
                        "type": "keyword"
                    },
                    "title": {
                        "type": "text",
                        "store": true,
                        "analyzer": "ik_max_word",
                        "search_analyzer": "ik_smart"
                    }
                }
            }
        }
    }
}

如果我强制把这个改成LONG,执行保存的时候,就会抛异常
图片说明
这是为什么呀,感觉好烦呀,虽然不影响我用,我也不会把ID设置成LONG,但是我搜遍了全网也没有找到有这类的问题,如果是官方就这么设计的,希望大家告诉我一下,顺便告诉我在哪看到的这么设计的,我的环境是

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
            <version>2.1.6.RELEASE</version>
        </dependency>

jdk是1.8
elasticsearch是6.2.4版本,我的强迫症都快犯了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
spring-data-elasticsearch 一对多

现在有三个实体类 关系是一个产品有多个属性 一个属性有多个属性值 如下: 实体类EsProduct: ``` @Document(indexName = "product", type = "productInfo",shards = 2,replicas = 1,refreshInterval = "-1") public class EsProduct implements Serializable { private static final long serialVersionUID = 2372551074091780419L; @Id private Long id; @Field(analyzer = "ik_max_word",type = FieldType.Text) private String productSn; private Long brandId; @Field(analyzer = "ik_max_word",type = FieldType.Text) private String brandName; private Long productCategoryId; @Field(analyzer = "ik_max_word",type = FieldType.Text) private String productName; private Long sale; @Field(analyzer = "ik_max_word",type = FieldType.Text) private String subTitle; private BigDecimal price; @Field(analyzer = "ik_max_word",type = FieldType.Text) private String keywords; private List<EsProductAttribute> attributeList; private EsProductCategory productCategorie; ``` 实体类EsProductAttribute: ``` public class EsProductAttribute implements Serializable { private static final long serialVersionUID = 4965902919813623705L; @Id private Long id; @Field(analyzer = "ik_max_word",type = FieldType.Text) private String paProductAttributeName;//属性名称 private List<EsProductAttributeValue> attributeValues; ``` 实体类EsProductAttributeValue: ``` public class EsProductAttributeValue implements Serializable { private static final long serialVersionUID = 6713756365860464751L; private Long id; @Field(analyzer = "ik_max_word",type = FieldType.Text) private String pavProductAttributeValue; ``` 之前的搜索是这样的,可以成功搜索 控制层代码: ``` @ApiOperation(value = "简单搜索:根据关键字,品牌名称或者产品名称,产品编号,副标题搜索(字符串:Text类型最大拆分)") @RequestMapping(value = "/search/keyword", method = RequestMethod.GET) @ResponseBody public CommonResult<CommonPage<EsProduct>> searchKeyword(@RequestParam(required = false) String keyword, @RequestParam(required = false, defaultValue = "0") Integer pageNum, @RequestParam(required = false, defaultValue = "5") Integer pageSize) { Page<EsProduct> esProductPage = esProductService.searchKeyword(keyword, pageNum, pageSize); return CommonResult.success(CommonPage.restPage(esProductPage)); } ``` 业务实现层代码: ``` @Autowired private EsProductRepository productRepository; @Override public Page<EsProduct> searchKeyword(String keyword, Integer pageNum, Integer pageSize) { Pageable pageable = PageRequest.of(pageNum, pageSize); return productRepository.findByKeywordsOrProductNameOrBrandNameOrProductSnOrSubTitle(keyword,keyword,keyword,keyword,keyword,pageable); } ``` EsProductRepository接口 ``` public interface EsProductRepository extends ElasticsearchRepository<EsProduct, Long> { /** * 根据关键字,产品名称,品牌名称,产品编号搜索 * @param keywords * @param productName * @param brandName * @param page * @return */ Page<EsProduct> findByKeywordsOrProductNameOrBrandNameOrProductSnOrSubTitle(String keywords,String productName,String brandName,String productSn,String subTitle,Pageable page); } ``` 都可以成功搜索 但是在进行属性和属性值搜索的时候告诉我说在EsProduct中找不到paProductAttributeName,我一想有道理,然后改变策略 单独写了一个接口测试 控制层 ``` @ApiOperation(value = "属性和属性值搜索、筛选、排序") @ApiImplicitParam(name = "sort", value = "排序字段:0->按相关度;1->按销量;2->价格从低到高;3->价格从高到低", defaultValue = "0", allowableValues = "0,1,2,3", paramType = "query", dataType = "integer") @RequestMapping(value = "/search", method = RequestMethod.GET) @ResponseBody public CommonResult<CommonPage<EsProduct>> search(@RequestParam(required = false) String keyword, @RequestParam(required = false, defaultValue = "0") Integer pageNum, @RequestParam(required = false, defaultValue = "5") Integer pageSize, @RequestParam(required = false, defaultValue = "0") Integer sort) { Page<EsProduct> esProductPage = esProductService.search(keyword,pageNum, pageSize, sort); return CommonResult.success(CommonPage.restPage(esProductPage)); } ``` 业务实现层: ``` @Override public Page<EsProduct> search(String keyword,Integer pageNum, Integer pageSize,Integer sort) { Pageable pageable = PageRequest.of(pageNum, pageSize); //将连接条件和聚合函数等组合 NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder(); //分页 nativeSearchQueryBuilder.withPageable(pageable); //搜索 if (StringUtils.isEmpty(keyword)) { nativeSearchQueryBuilder.withQuery(QueryBuilders.matchAllQuery()); } else { List<FunctionScoreQueryBuilder.FilterFunctionBuilder> filterFunctionBuilders = new ArrayList<>(); //QueryBuilders:简单的静态工厂”导入静态”使用。主要作用是查询条件(关系),如区间\精确\多值等条件 //属性名称 filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("paProductAttributeName", keyword), ScoreFunctionBuilders.weightFactorFunction(2))); //属性值 filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("value", keyword), ScoreFunctionBuilders.weightFactorFunction(2))); //产品名称 // filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("productName",keyword), // ScoreFunctionBuilders.weightFactorFunction(2))); // //关键字 // filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("keywords", keyword), // ScoreFunctionBuilders.weightFactorFunction(2))); // //产品编号 // filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("productSn", keyword), // ScoreFunctionBuilders.weightFactorFunction(2))); FunctionScoreQueryBuilder.FilterFunctionBuilder[] builders = new FunctionScoreQueryBuilder.FilterFunctionBuilder[filterFunctionBuilders.size()]; filterFunctionBuilders.toArray(builders); FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery(builders) .scoreMode(FunctionScoreQuery.ScoreMode.SUM) .setMinScore(2); nativeSearchQueryBuilder.withQuery(functionScoreQueryBuilder); } // //排序 // if(sort==1){ // //按销量从高到低 // nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("sale").order(SortOrder.DESC)); // }else if(sort==2){ // //按价格从低到高 // nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("price").order(SortOrder.ASC)); // }else if(sort==3){ // //按价格从高到低 // nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("price").order(SortOrder.DESC)); // }else{ // //按相关度 // nativeSearchQueryBuilder.withSort(SortBuilders.scoreSort().order(SortOrder.DESC)); // } nativeSearchQueryBuilder.withSort(SortBuilders.scoreSort().order(SortOrder.DESC)); NativeSearchQuery searchQuery = nativeSearchQueryBuilder.build(); LOGGER.info("DSL:{}", searchQuery.getQuery().toString()); return productRepository.search(searchQuery); } ``` es中的数据是: ``` { "code": 200, "message": "操作成功", "data": { "pageNum": 0, "pageSize": 5, "totalPage": 4, "total": 17, "list": [ { "id": 40, "productSn": "C146179 ", "brandId": null, "brandName": "PSA(信昌电陶)", "productCategoryId": 54, "productName": "贴片电容/220nF(224)±10%250V编带", "sale": 1000, "subTitle": "贴片电容", "price": null, "keywords": "贴片电容/220nF(224) ±10% 250V 编带 ", "attributeList": [ { "id": 49, "paProductAttributeName": "容值", "attributeValues": [ { "id": 240, "pavProductAttributeValue": "0.1pf" }, { "id": 241, "pavProductAttributeValue": "0.2pf" }, { "id": 242, "pavProductAttributeValue": "0.25pf" }, { "id": 243, "pavProductAttributeValue": "0.3pf" }, { "id": 244, "pavProductAttributeValue": "0.4pf" } ] }, { "id": 51, "paProductAttributeName": "额定电压", "attributeValues": [ { "id": 290, "pavProductAttributeValue": "4v" }, { "id": 292, "pavProductAttributeValue": "10v" }, { "id": 296, "pavProductAttributeValue": "30v" } ] } ], "productCategorie": { "id": 54, "productCategoryName": "贴片电容" } }, { "id": 41, "productSn": "C394163 ", "brandId": null, "brandName": "PSA(信昌电陶)", "productCategoryId": 54, "productName": "贴片电容/10nF(103) ±10% 1KV", "sale": 1000, "subTitle": "贴片电容", "price": null, "keywords": "贴片电容/10nF(103) ±10% 1KV ", "attributeList": [ { "id": 49, "paProductAttributeName": "容值", "attributeValues": [ { "id": 245, "pavProductAttributeValue": "0.5pf" }, { "id": 246, "pavProductAttributeValue": "0.6pf" }, { "id": 247, "pavProductAttributeValue": "0.68pf" } ] }, { "id": 50, "paProductAttributeName": "精度", "attributeValues": [ { "id": 272, "pavProductAttributeValue": "+0.05pf" }, { "id": 273, "pavProductAttributeValue": "+0.1pf" }, { "id": 274, "pavProductAttributeValue": "+0.25pf" } ] }, { "id": 51, "paProductAttributeName": "额定电压", "attributeValues": [ { "id": 291, "pavProductAttributeValue": "6.3v" }, { "id": 293, "pavProductAttributeValue": "16v" }, { "id": 297, "pavProductAttributeValue": "35v" } ] } ], "productCategorie": { "id": 54, "productCategoryName": "贴片电容" } }, { "id": 44, "productSn": "C342641 ", "brandId": null, "brandName": "TDK", "productCategoryId": 54, "productName": "贴片电容/47nF(473) ±5% 100V 编带", "sale": 1000, "subTitle": "贴片电容", "price": null, "keywords": "贴片电容/47nF(473) ±5% 100V 编带 ", "attributeList": [ { "id": 49, "paProductAttributeName": "容值", "attributeValues": [ { "id": 254, "pavProductAttributeValue": "1.3pf" }, { "id": 255, "pavProductAttributeValue": "1.4pf" }, { "id": 256, "pavProductAttributeValue": "2pf" }, { "id": 257, "pavProductAttributeValue": "2.1pf" } ] }, { "id": 50, "paProductAttributeName": "精度", "attributeValues": [ { "id": 278, "pavProductAttributeValue": "+5%" } ] } ], "productCategorie": { "id": 54, "productCategoryName": "贴片电容" } }, { "id": 48, "productSn": "C11366 ", "brandId": null, "brandName": " AVX", "productCategoryId": 55, "productName": "钽电容/22uF(226) ±10% 10V", "sale": 1000, "subTitle": "钽电容", "price": null, "keywords": "钽电容/22uF(226) ±10% 10V ", "attributeList": [ { "id": 49, "paProductAttributeName": "容值", "attributeValues": [ { "id": 269, "pavProductAttributeValue": "0.1pf" }, { "id": 270, "pavProductAttributeValue": "0.2pf" } ] }, { "id": 50, "paProductAttributeName": "精度", "attributeValues": [ { "id": 271, "pavProductAttributeValue": "+0.02pf" }, { "id": 284, "pavProductAttributeValue": "-20%,+80%" } ] } ], "productCategorie": { "id": 55, "productCategoryName": "钽电容" } }, { "id": 52, "productSn": "C391913 ", "brandId": null, "brandName": "SAMYOUNG(韩国三莹)", "productCategoryId": 56, "productName": "贴片电解电容/10uF ±20% 50V", "sale": 1000, "subTitle": "贴片电解电容", "price": null, "keywords": "贴片电解电容/10uF ±20% 50V ", "attributeList": [], "productCategorie": { "id": 56, "productCategoryName": "贴片电解电容" } } ] } } ``` 然后搜索了半天一点反应也没有,也没有头绪,求助大神指点

spring-data-elasticsearch 字段如何驼峰转下划线

最近使用spring-data-elasticsearch,但是想在es中存储的时候使用下划线,请问各位大神有啥解决方案

使用spring-data API 搜索es 集合类型数据

使用spring-data-es API进行 es 搜索 建的索引中 有个 字段 List<String> 类型。 如何搜索这种类型。 尝试了下面这种方式,没法搜索成功。 ``` boolQueryBuilder.must(QueryBuilders.termQuery("consignCodeList",invoiceQueryPageB.getInvoiceConsignCode())); ``` 请求下,有遇到类似问题的大神吗,指点一下。

spring-data-elasticsearch 创建geo_point 类型不生效

最近在用spring-data-elasticsearch 在做距离应用时创建geo_point 类型时发现有时候会不生效(注意是有时候不生效,不知道是哪里影响的,很妖),正常情况下type 应该是geo_point,但是有时候创建出来的是一个嵌套类型,包含两个double属性的type 实体类加了注解如下 @GeoPointField private GeoPoint shipperPoint; 创建出来的正确类型如下图: ![图片说明](https://img-ask.csdn.net/upload/201507/14/1436879872_437791.png) 创建出来的错误类型如下图: ![图片说明](https://img-ask.csdn.net/upload/201507/14/1436879901_603114.png) 不知道是什么原因导致的geo_point 类型不生效? 求大神指导?

Spring Data Elasticsearch @Query 报错

按照spring官方文档显示的做,eclipse报Syntax error on tokens。 ``` public interface BookRepository extends ElasticsearchRepository<Book, String> { @Query("{"bool" : {"must" : {"field" : {"name" : "?0"}}}}") Page<Book> findByName(String name,Pageable pageable); } ```

spring-boot与elasticsearch整合时如何定义内嵌对象的分词策略

@Document(indexName = "logmodel", type = "logs", shards = 4, replicas = 1,indexStoreType="fs", refreshInterval = "-1") public class LogES { @Id private String id; private String itcode; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String ip; private String ad_type; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String telephone; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String mobile; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String email; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String firstname; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String firstnameen; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String boss; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String position; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String organization; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String country; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String cityname; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String givenname; private String employeeNumber; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String employeetype; private boolean ismanager; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String bossname; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String bigboss; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String bigbossname; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String enterprise; @JsonFormat (shape = JsonFormat.Shape.STRING, pattern ="yyyy-MM-dd'T'hh:mm:ss.SSS'Z'") private Date dt; private String dev_platform; private String app_version; private String dev_version; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String dev_info; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String dev_imei; @Field(type = FieldType.String,index = FieldIndex.not_analyzed) private String func; @Field( type = FieldType.Auto) private Object content; private CochatResponseEntity cochatResponseEntity; 比如怎么设置content对象内部字段的分词策略,如:@Field(type = FieldType.String,index = FieldIndex.not_analyzed)

spring data 更新问题

有两个表 partyout:id,memberid partymember id(和上一个memberid链接)isdel 用spring data ,@Query()这种方式怎么通过partyout的id去更新isdel得值,query里面怎么写啊!![![![图片说明](https://img-ask.csdn.net/upload/201608/17/1471420666_529687.png)图片说明](https://img-ask.csdn.net/upload/201608/17/1471420652_315518.png)图片说明](https://img-ask.csdn.net/upload/201608/17/1471420647_475913.png)

使用spring data es如何使用SUM方法

``` Criteria criteria = new Criteria(); CriteriaQuery criteriaQuery = new CriteriaQuery(criteria); elasticsearchTemplate.queryForObject(criteriaQuery, MerchantSummaryData.class); ``` 使用spring data es如何使用SUM方法 ES 中有个SumBuilder方法 怎么和spring data es 结合起来 SumBuilder field2Sum = AggregationBuilders.sum("sum_field2").field("field2");

求助sprinboot整合 elasticsearch-rest-high-level-client-5.6.4报错

以下是报错信息: Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientConfigurations$RestHighLevelClientConfiguration.elasticsearchRestHighLevelClient(RestClientConfigurations.java:75) The following method did not exist: org.elasticsearch.client.RestHighLevelClient.<init>(Lorg/elasticsearch/client/RestClientBuilder;)V The method's class, org.elasticsearch.client.RestHighLevelClient, is available from the following locations: jar:file:/Users/jianxiaowen/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/5.6.4/elasticsearch-rest-high-level-client-5.6.4.jar!/org/elasticsearch/client/RestHighLevelClient.class It was loaded from the following location: file:/Users/jianxiaowen/.m2/repository/org/elasticsearch/client/elasticsearch-rest-high-level-client/5.6.4/elasticsearch-rest-high-level-client-5.6.4.jar Action: Correct the classpath of your application so that it contains a single, compatible version of org.elasticsearch.client.RestHighLevelClient 以下是pom文件,是springboot版本和这个es不兼容吗,原来用的es6.x是可以的,换成5.x就不行了,但是公司环境就要求5.x: ``` <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.xxx</groupId> <artifactId>repservice</artifactId> <version>1.0</version> <modules> <module>kg-business</module> </modules> <packaging>pom</packaging> <name>repservice</name> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.7.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <elasticsearch.version>5.6.4</elasticsearch.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>com.x x x.datanlp</groupId> <artifactId>graph-db-sdk</artifactId> <version>1.1-SNAPSHOT</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.13</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-commons</artifactId> <version>2.1.10.RELEASE</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.restdocs</groupId> <artifactId>spring-restdocs-mockmvc</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.0</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter-test</artifactId> <version>2.1.0</version> <scope>test</scope> </dependency> <dependency> <groupId>org.flywaydb</groupId> <artifactId>flyway-core</artifactId> <version>5.2.4</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.3</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>4.4.12</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.10</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpmime</artifactId> <version>4.5.10</version> </dependency> <dependency> <groupId>io.reactivex.rxjava2</groupId> <artifactId>rxjava</artifactId> <version>2.2.9</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> <version>3.6</version> </dependency> <!-- 引入 redis 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.solr/solr-solrj --> <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-solrj</artifactId> <version>8.2.0</version> </dependency> <!-- 解压rar --> <dependency> <groupId>com.github.junrar</groupId> <artifactId>junrar</artifactId> <version>4.0.0</version> </dependency> <!-- 解压zip --> <dependency> <groupId>org.apache.ant</groupId> <artifactId>ant</artifactId> <version>1.10.7</version> </dependency> <!--结果验证--> <dependency> <groupId>com.jayway.jsonpath</groupId> <artifactId>json-path</artifactId> <version>2.4.0</version> </dependency> <!-- 临时--> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.51</version> </dependency> <dependency> <groupId>com.arangodb</groupId> <artifactId>arangodb-java-driver</artifactId> <version>5.0.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-web --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-web</artifactId> <version>2.7</version> </dependency> <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>5.6.4</version> </dependency> <!-- Java Low Level REST Client --> <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-client</artifactId> <version>5.6.4</version> </dependency> <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-high-level-client</artifactId> <version>5.6.4</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> ```

java连接elasticsearch抛异常None of the configured nodes are available

阿里云上docker方式部署了单节点的6.5.3版本的es,elasticsearch.yml配置如下: ``` cluster.name: "docker-cluster" node.name: node-test network.bind_host: 0.0.0.0 network.publish_host: 58.87.73.232 discovery.zen.ping.unicast.hosts: ["58.87.73.232:9300"] discovery.zen.minimum_master_nodes: 1 http.cors.enabled: true http.cors.allow-origin: "*" ``` 通过springboot2.1.1项目集成spring-boot-starter-data-elasticsearch application.properties配置如下: ``` spring.data.elasticsearch.cluster-name=docker-cluster spring.data.elasticsearch.cluster-nodes=58.87.73.232:9300 ``` 启动项目的测试用例抛异常**NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{rLnGNbz3QFaEToPtiuFTgQ}{58.87.73.232}{58.87.73.232:9300}]] ** 请问什么原因? 附节点状态截图: ![图片说明](https://img-ask.csdn.net/upload/201909/10/1568100643_439007.png)

Elasticsearch 启动报错问题 显示Nodes的问题???

今天在搭建ElasticSearch时候 出现的问题 显示Nodes的问题: ``` 019-01-18 23:20:34.462 ERROR 12264 --- [ main] .d.e.r.s.AbstractElasticsearchRepository : failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{mfQlD8ZeTIOtTnLapBR5pA}{192.168.1.105}{192.168.1.105:9300}] ``` springboot版本: <version>2.1.2.RELEASE</version> springboot data elasticsearch 版本: ![图片说明](https://img-ask.csdn.net/upload/201901/18/1547825326_146679.png) properties配置文件内容如下: ``` spring.elasticsearch.jest.uris=http://192.168.1.105:9200/ spring.data.elasticsearch.cluster-name=elasticsearch spring.data.elasticsearch.cluster-nodes=192.168.1.105:9300 ``` elasticsearch 浏览器中显示如下: ``` { "name" : "Rigellian Recorder", "cluster_name" : "elasticsearch", "cluster_uuid" : "MU7QHYyfR6CoTImE1BpjEQ", "version" : { "number" : "2.4.6", "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd", "build_timestamp" : "2017-07-18T12:17:44Z", "build_snapshot" : false, "lucene_version" : "5.5.4" }, "tagline" : "You Know, for Search" } ```

springboot整合elasticsearch提示org.elasticsearch.transport.NodeDisconnectedException

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId> <version>2.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-elasticsearch</artifactId> <version>2.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>2.4.0</version> </dependency> <dependency> <groupId>org.elasticsearch.plugin</groupId> <artifactId>transport-netty4-client</artifactId> <version>6.4.0</version> </dependency> <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>transport</artifactId> <version>6.4.0</version> </dependency> application.yml 配置如下: spring: data: elasticsearch: cluster-nodes: 192.168.100.21:9300,192.168.100.22:9300,192.168.100.23:9300 cluster-name: wt repositories: enabled: true springboot版本1.5.8,linux安装ES版本是6.4.0,上面是工程里引入的jar,ES在浏览器能访问,且有数据,但是项目启动就连接不上 NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{192.168.100.21}{192.168.100.21:9300}, {#transport#-2}{192.168.100.22}{192.168.100.22:9300}, {#transport#-3}{192.168.100.23}{192.168.100.23:9300}] ] at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:290) at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:207) at org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55) at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:288)

spring的aop和elasticsearch

我已经把一个数据库导入到了elasticsearch中,但是如果以后我对这个数据库进行增删查改,elasticsearch没有改变,老师告诉我用aop的话一个方法就可以解决,请问怎么实现啊?

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource

``` 2020-04-20 09:28:15.841 ERROR 11300 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport$AutoConfiguredAnnotationRepositoryConfigurationSource.<init>(AbstractRepositoryConfigurationSourceSupport.java:128) The following method did not exist: org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.<init>(Lorg/springframework/core/type/AnnotationMetadata;Ljava/lang/Class;Lorg/springframework/core/io/ResourceLoader;Lorg/springframework/core/env/Environment;Lorg/springframework/beans/factory/support/BeanDefinitionRegistry;Lorg/springframework/beans/factory/support/BeanNameGenerator;)V The method's class, org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource, is available from the following locations: jar:file:/F:/Maven/localRepository/repository/org/springframework/data/spring-data-commons/2.1.5.RELEASE/spring-data-commons-2.1.5.RELEASE.jar!/org/springframework/data/repository/config/AnnotationRepositoryConfigurationSource.class It was loaded from the following location: file:/F:/Maven/localRepository/repository/org/springframework/data/spring-data-commons/2.1.5.RELEASE/spring-data-commons-2.1.5.RELEASE.jar Action: Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource Process finished with exit code 1 ``` 这个报错是jar包冲突吗?弄了好长时间没弄出来,求助

Spring Data jpa+Mongodb查询全部数据出错

代码: List<Comment> comments = commentDao.findAll(); findAll为继承自MongoRepository的方法 报错: Caused by: com.mongodb.MongoQueryException: Query failed with error code 2 and error message 'Field 'locale' is invalid in: { locale: "comment" }' on server localhost:27017 at com.mongodb.operation.FindOperation$1.call(FindOperation.java:735) at com.mongodb.operation.FindOperation$1.call(FindOperation.java:725) at com.mongodb.operation.OperationHelper.withReadConnectionSource(OperationHelper.java:463) at com.mongodb.operation.FindOperation.execute(FindOperation.java:725) at com.mongodb.operation.FindOperation.execute(FindOperation.java:89) at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:189) at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:143) at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:92) at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:2793) ... 86 more 试过换工程、换数据库、换表、换版本,依旧没有解决,而且几乎搜不到这个错误。

elasticsearch连接出错

1、错误截图 ``` 2019-12-06 10:39:43.846 ERROR 2824 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{OAnbfg_bSjCat5ebeRNMTg}{127.0.0.1}{127.0.0.1:9300}]]] with root cause org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{OAnbfg_bSjCat5ebeRNMTg}{127.0.0.1}{127.0.0.1:9300}] at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:347) ~[elasticsearch-5.6.1.jar:5.6.1] at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:245) ~[elasticsearch-5.6.1.jar:5.6.1] at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59) ~[elasticsearch-5.6.1.jar:5.6.1] at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:363) ~[elasticsearch-5.6.1.jar:5.6.1] at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:408) ~[elasticsearch-5.6.1.jar:5.6.1] at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80) ~[elasticsearch-5.6.1.jar:5.6.1] at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54) ~[elasticsearch-5.6.1.jar:5.6.1] at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:62) ~[elasticsearch-5.6.1.jar:5.6.1] at com.imooc.service.search.SearchServiceImpl.aggregateDistrictHouse(SearchServiceImpl.java:460) ~[classes/:na] at com.imooc.web.controller.house.HouseController.show(HouseController.java:207) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-webmvc-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) ~[spring-webmvc-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.3.11.RELEASE.jar:4.3.11.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) ~[tomcat-embed-core-8.5.20.jar:8.5.20] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.11.RELEASE.jar:4.3.11.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.20.jar:8.5.20] ``` ![图片说明](https://img-ask.csdn.net/upload/201912/06/1575600402_940718.jpg) 2、elasticsearch配置信息 ``` cluster.name: elasticsearch # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: master node.master: true node.data: true # # Add custom attributes to the node: # #node.attr.rack: r1 # # ----------------------------------- Paths ------------------------------------ # # Path to directory where to store the data (separate multiple locations by comma): # #path.data: /path/to/data # # Path to log files: # #path.logs: /path/to/logs # # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: # #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. # # ---------------------------------- Network ----------------------------------- # # Set the bind address to a specific IP (IPv4 or IPv6): # network.host: 127.0.0.1 # # Set a custom port for HTTP: # #http.port: 9200 # # For more information, consult the network module documentation. # # --------------------------------- Discovery ---------------------------------- # # 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): # #discovery.zen.minimum_master_nodes: 3 # # For more information, consult the zen discovery module documentation. # # ---------------------------------- Gateway ----------------------------------- # # Block initial recovery after a full cluster restart until N nodes are started: # #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 #bootstrap.system_call_filter: false http.cors.enabled: true http.cors.allow-origin: "*" ``` 3、spring项目配置信息 ``` package com.imooc.config; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.transport.client.PreBuiltTransportClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.net.InetAddress; import java.net.UnknownHostException; @Configuration public class ElasticSearchConfig { @Value("${elasticsearch.host}") private String esHost; @Value("${elasticsearch.port}") private int esPort; @Value("${elasticsearch.cluster.name}") private String esName; @Bean public TransportClient esClient() throws UnknownHostException { Settings settings = Settings.builder() .put("cluster.name", this.esName) // .put("cluster.name", "elasticsearch") .put("client.transport.sniff", true) .build(); InetSocketTransportAddress master = new InetSocketTransportAddress( InetAddress.getByName(esHost), esPort // InetAddress.getByName("192.168.100.106"), 8999 ); TransportClient client = new PreBuiltTransportClient(settings) .addTransportAddress(master); return client; } } ``` 4、application.propertires ``` elasticsearch.cluster.name=xunwu elasticsearch.host=127.0.0.1 elasticsearch.port=9300 ```

elasticsearch时间映射问题

这个是映射的时间设置 ``` ",\"updateTimes\":{\"type\":\"date\", \"format\": \"yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis\"}" ``` 这个是导入的时间格式,类型是date的 ``` "createTimes" : ISODate("2018-03-24T03:25:47.020Z"), ``` 报出的错误: ``` "reason":"Invalid format: "2018-06-08T20:52:49" is malformed at "T20:52:49"" ```

为什么 elasticsearch 获取节点信息失败?

在 spring boot 项目中即成集成 elasticsearch(dao层数据与es交互使用的的是 spring-data-elasticsearch)首先安装了服务器端的 es 服务,和 head 插件,es 服务启动正常,node-1 为默认主节点,my-cluster 为集群名,如图: ![图片说明](https://img-ask.csdn.net/upload/201605/24/1464076273_991814.png) 在程序中,使用嵌入式node启动节点正常,方式如下: ``` Node node = NodeBuilder.nodeBuilder().node(); node.start(); ``` 但是,如果使用 TransportClient 建立 es 的 Client,方式如下: ``` TransportClient client = new TransportClient(settings); client.addTransportAddress(new InetSocketTransportAddress("127.0.0.1", 9300)); ``` 这是 ES 2.3 官网上面提供的 TransportClient 方式:https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html 使用 TransportClient 方式,启动程序后,程序可以正常启动,但是控制台一直不停报错,貌似是在一直监测节点,而节点一直没有被发现,所以不停报错,错误信息如下,应用程序控制台错误信息: ``` 2016-05-23 19:40:15.823 INFO 27655 --- [ main] org.elasticsearch.client.transport : [Aliyah Bishop] failed to get node info for [#transport#-1][XXX-MBP.lan][inet[/127.0.0.1:9300]], disconnecting... org.elasticsearch.transport.RemoteTransportException: Failed to deserialize exception response from stream Caused by: org.elasticsearch.transport.TransportSerializationException: Failed to deserialize exception response from stream at org.elasticsearch.transport.netty.MessageChannelHandler.handlerResponseError(MessageChannelHandler.java:173) at org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:125) at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791) at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:296) at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462) at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443) at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303) at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559) at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:268) at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:255) at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88) at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108) at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318) at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89) at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178) at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: java.io.StreamCorruptedException: Unsupported version: 1 at org.elasticsearch.common.io.ThrowableObjectInputStream.readStreamHeader(ThrowableObjectInputStream.java:46) at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299) at org.elasticsearch.common.io.ThrowableObjectInputStream.<init>(ThrowableObjectInputStream.java:38) at org.elasticsearch.transport.netty.MessageChannelHandler.handlerResponseError(MessageChannelHandler.java:170) ... 23 common frames omitted …………. failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [] ``` es 控制台报错信息: ``` [2016-05-23 21:45:56,807][WARN ][transport.netty ] [node-1] exception caught on transport layer [[id: 0x8e4b89bc, /127.0.0.1:62566 => /127.0.0.1:9300]], closing connection java.lang.IllegalStateException: Message not fully read (request) for requestId [233], action [cluster/nodes/info], readerIndex [39] vs expected [57]; resetting at org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:121) at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296) at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462) at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443) at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303) at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791) at org.elasticsearch.common.netty.OpenChannelsHandler.handleUpstream(OpenChannelsHandler.java:75) at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255) at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88) at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108) at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337) at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89) at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178) at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) ``` 而且,当我使用嵌入式node启动节点后,系统会自动启动一个node节点,node.name 也是随机的,并且并没有将该节点加入启动的es集群中,我加入的索引和数据也不能出现在 my-cluster 集群中 所以有两个问题: 1、为什么我使用嵌入式node启动节点,启动后的节点不会加入到集群中? 2、使用 TransportClient 方式建立 Client,启动程序后,程序的控制台,和服务器端的es一直报错,获取节点信息失败,是什么原因?即上面的错误信息 下面是环境版本信息: 服务器端 es 版本:2.3.3 jdk 版本:1.7.0_79 spring-data-elasticsearch 版本:1.2.0.RELEASE(即:elasticsearch-1.4.4.jar) 服务器端 es 配置,elasticsearch.yml: cluster.name: my-cluster node.name: node-1 http 端口为:9200 节点间的通信端口为:9300 关于第二个问题尝试了很多解决方案,比如: 1、应用 和 es 的 jdk 环境版本不一致。已检查过一致 https://github.com/elastic/elasticsearch/issues/3835 2、es 多个节点之间的JDK版本不一致。我使用的只是单节点,并且都在我本地机器上 http://jontai.me/blog/2013/06/elasticsearch-remotetransportexception-failed-to-deserialize-exception-response-from-stream/ 3、idk 版本过低,建议1.7+。已是1.7+ 最后附上两种启动节点方式的完整代码 1、嵌入式 node 启动 ``` import org.elasticsearch.client.Client; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; @Configuration @EnableElasticsearchRepositories(basePackages = "xx.xxx.domain.repository.elastic") public class ElasticsearchConfiguration { @Bean public Client client() { Node node = NodeBuilder.nodeBuilder().node(); node.start(); return node.client(); } } ``` 2、TransportClient 方式 ``` import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.elasticsearch.core.ElasticsearchOperations; import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; @Configuration @EnableElasticsearchRepositories(basePackages = "xx.xxx.domain.repository.elastic") public class ElasticsearchConfiguration { @Bean public Client client() { TransportClient client = new TransportClient(); client.addTransportAddress(new InetSocketTransportAddress("127.0.0.1", 9300)); return client; } @Bean public ElasticsearchOperations elasticsearchTemplate() { return new ElasticsearchTemplate(client()); } } ```

spring 整合 es 中的 ElasticsearchRepository

springboot 本人已经 整合完毕,es配置直接写在配置文件中, 然后按照网上的配置就可以使用ElasticsearchRepository。 但是如果是spring的话 会有问题,ElasticsearchRepository 这个类的 子类 应该是不同实例化的,也就是不用给他加@Bean这些注解, 但是我发现如果在spring中 这个类的加载会报错,内容如下 ``` 2018-12-23 01:58:11.252 [main] INFO o.s.context.support.DefaultLifecycleProcessor - Starting beans in phase 2147483647 2018-12-23 01:58:11.260 [main] INFO o.s.s.a.ScheduledAnnotationBeanPostProcessor - No TaskScheduler/ScheduledExecutorService bean found for scheduled processing 2018-12-23 01:58:11.279 [main] ERROR o.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@9573584] to prepare test instance [com.qinwell.tbcrm.task.test.es.ApiDemo@74919649] org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.qinwell.tbcrm.task.test.es.ApiDemo': Unsatisfied dependency expressed through field 'memberRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.qinwell.tbcrm.task.test.es.MemberRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:386) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.qinwell.tbcrm.task.test.es.MemberRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1493) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ... 27 common frames omitted 2018-12-23 01:58:11.291 [Thread-7] INFO o.s.context.support.GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext@1984b1f: startup date [Sun Dec 23 01:57:57 CST 2018]; root of context hierarchy 2018-12-23 01:58:11.293 [Thread-7] INFO o.s.context.support.DefaultLifecycleProcessor - Stopping beans in phase 2147483647 Disconnected from the target VM, address: '127.0.0.1:60154', transport: 'socket' Process finished with exit code 255 ```

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

点沙成金:英特尔芯片制造全过程揭密

“亚马逊丛林里的蝴蝶扇动几下翅膀就可能引起两周后美国德州的一次飓风……” 这句人人皆知的话最初用来描述非线性系统中微小参数的变化所引起的系统极大变化。 而在更长的时间尺度内,我们所生活的这个世界就是这样一个异常复杂的非线性系统…… 水泥、穹顶、透视——关于时间与技艺的蝴蝶效应 公元前3000年,古埃及人将尼罗河中挖出的泥浆与纳特龙盐湖中的矿物盐混合,再掺入煅烧石灰石制成的石灰,由此得来了人...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

外包程序员的幸福生活

今天给你们讲述一个外包程序员的幸福生活。男主是Z哥,不是在外包公司上班的那种,是一名自由职业者,接外包项目自己干。接下来讲的都是真人真事。 先给大家介绍一下男主,Z哥,老程序员,是我十多年前的老同事,技术大牛,当过CTO,也创过业。因为我俩都爱好喝酒、踢球,再加上住的距离不算远,所以一直也断断续续的联系着,我对Z哥的状况也有大概了解。 Z哥几年前创业失败,后来他开始干起了外包,利用自己的技术能...

C++11:一些微小的变化(新的数据类型、template表达式内的空格、nullptr、std::nullptr_t)

本文介绍一些C++的两个新特性,它们虽然微小,但对你的编程十分重要 一、Template表达式内的空格 C++11标准之前建议在“在两个template表达式的闭符之间放一个空格”的要求已经过时了 例如: vector&lt;list&lt;int&gt; &gt;; //C++11之前 vector&lt;list&lt;int&gt;&gt;; //C++11 二、nullptr ...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

深入剖析Springboot启动原理的底层源码,再也不怕面试官问了!

大家现在应该都对Springboot很熟悉,但是你对他的启动原理了解吗?

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

【阿里P6面经】二本,curd两年,疯狂复习,拿下阿里offer

二本的读者,在老东家不断学习,最后逆袭

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

微软为一人收购一公司?破解索尼程序、写黑客小说,看他彪悍的程序人生!...

作者 | 伍杏玲出品 | CSDN(ID:CSDNnews)格子衬衫、常掉发、双肩包、修电脑、加班多……这些似乎成了大众给程序员的固定标签。近几年流行的“跨界风”开始刷新人们对程序员的...

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

我说我懂多线程,面试官立马给我发了offer

不小心拿了几个offer,有点烦

自从喜欢上了B站这12个UP主,我越来越觉得自己是个废柴了!

不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...

立即提问
相关内容推荐