Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot Elasticsearch高级rest客户端无法映射地理点_Spring Boot_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Resthighlevelclient - Fatal编程技术网 elasticsearch,resthighlevelclient,Spring Boot,elasticsearch,Resthighlevelclient" /> elasticsearch,resthighlevelclient,Spring Boot,elasticsearch,Resthighlevelclient" />

Spring boot Elasticsearch高级rest客户端无法映射地理点

Spring boot Elasticsearch高级rest客户端无法映射地理点,spring-boot,elasticsearch,resthighlevelclient,Spring Boot,elasticsearch,Resthighlevelclient,我有一个使用elasticsearch geospatial的应用程序。我正在使用elasticsearch rest客户端对文档进行索引和搜索。当我将一个geo_点字段索引为elastic时,我无法搜索它们。我有个例外 我的对象类 import lombok.Data; import org.elasticsearch.common.geo.GeoPoint; import javax.persistence.Id; @Data public class CustomerLocation {

我有一个使用elasticsearch geospatial的应用程序。我正在使用elasticsearch rest客户端对文档进行索引和搜索。当我将一个geo_点字段索引为elastic时,我无法搜索它们。我有个例外

我的对象类

import lombok.Data;
import org.elasticsearch.common.geo.GeoPoint;
import javax.persistence.Id;

@Data
public class CustomerLocation {
    @Id
    private String id;

    private Integer cifNo;

    private String userId;

    private String status;

    private String sessionId;

    private Integer locationCount;

    private String lastSeenDate;

    private String firstSeenDate;

    private GeoPoint geoPoint;
}
创建索引方法

public void save(CustomerLocation customerLocation) throws IOException {
    IndexRequest indexRequest = new IndexRequest("customerlocation").id(customerLocation.getId()).source(objectMapper.writeValueAsString(customerLocation),XContentType.JSON);
    client.index(indexRequest, RequestOptions.DEFAULT);
}
索引映射

{
    "customerlocation": {
        "mappings": {
            "properties": {
                "cifNo": {
                    "type": "long"
                },
                "firstSeenDate": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "geoPoint": {
                    "properties": {
                        "fragment": {
                            "type": "boolean"
                        },
                        "geohash": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "lat": {
                            "type": "float"
                        },
                        "lon": {
                            "type": "float"
                        }
                    }
                },
                "id": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "lastSeenDate": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "locationCount": {
                    "type": "long"
                },
                "status": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }
            }
        }
    }
}
而且,地质点场不是地质点类型。当我搜索一个半径如下的位置时

public List<CustomerLocation> findByCifNoAndUserIdWithinLocation(GenericRequest genericRequest, Integer radius) {

    List<CustomerLocation> customerLocationList = new ArrayList<>();
    try {
        SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
        SearchRequest searchRequest = new SearchRequest("customerlocation");

        QueryBuilder query;
        if(genericRequest.getUserId()!=null) {
            query = QueryBuilders.boolQuery().
                    filter(QueryBuilders.termQuery("cifNo",genericRequest.getClientNo())).
                    filter(QueryBuilders.termQuery("userId",genericRequest.getUserId()));
        } else {
            query = QueryBuilders.boolQuery().
                    filter(QueryBuilders.termQuery("cifNo",genericRequest.getClientNo()));
        }
        QueryBuilder geoDistanceQueryBuilder = QueryBuilders
                .geoDistanceQuery("geoPoint")
                .point(genericRequest.getLatitude(), genericRequest.getLongitude())
                .distance(radius, DistanceUnit.KILOMETERS);

        QueryBuilder finalQuery = QueryBuilders.boolQuery().must(query).filter(geoDistanceQueryBuilder);
        sourceBuilder.query(finalQuery);
        searchRequest.source(sourceBuilder);

        SearchResponse searchResponse = client.search(searchRequest,RequestOptions.DEFAULT);
        SearchHit[] hits = searchResponse.getHits().getHits();
        for (SearchHit searchHit:hits) {
            CustomerLocation customerLocation = objectMapper.readValue(searchHit.getSourceAsString(),CustomerLocation.class);
            if(customerLocation.getStatus()!=null && !customerLocation.getStatus().equalsIgnoreCase("alert")) {
                customerLocationList.add(customerLocation);
            } else if (customerLocation.getStatus()==null) {
                customerLocationList.add(customerLocation);
            }
        }
    } catch (Exception e) {
        log.error("[{}]Exception occured while getting customer location from elastic",genericRequest.getClientNo(),e);
    }
    return customerLocationList;
}
公共列表通过IfNoAndUserInLocation(GenericRequest GenericRequest,整数半径)查找{
List customerLocationList=新建ArrayList();
试一试{
SearchSourceBuilder sourceBuilder=新的SearchSourceBuilder();
SearchRequest SearchRequest=新的SearchRequest(“customerlocation”);
QueryBuilder查询;
if(genericRequest.getUserId()!=null){
query=QueryBuilders.boolQuery()。
过滤器(QueryBuilders.termQuery(“cifNo”,genericRequest.getClientNo()))。
过滤器(QueryBuilders.termQuery(“userId”,generirequest.getUserId());
}否则{
query=QueryBuilders.boolQuery()。
过滤器(QueryBuilders.termQuery(“cifNo”,generirequest.getClientNo());
}
QueryBuilder地理距离QueryBuilder=QueryBuilder
.地理距离查询(“地理点”)
.point(genericRequest.getLatitude(),genericRequest.getLatitude())
.距离(半径、距离单位为公里);
QueryBuilder finalQuery=QueryBuilders.boolQuery().must(query).filter(geoDistanceQueryBuilder);
sourceBuilder.query(finalQuery);
searchRequest.source(sourceBuilder);
SearchResponse SearchResponse=client.search(searchRequest,RequestOptions.DEFAULT);
SearchHit[]hits=searchResponse.getHits().getHits();
用于(搜索命中搜索命中:命中){
CustomerLocation CustomerLocation=objectMapper.readValue(searchHit.getSourceAsString(),CustomerLocation.class);
if(customerLocation.getStatus()!=null&!customerLocation.getStatus().equalsIgnoreCase(“警报”)){
customerLocationList.add(customerLocation);
}else if(customerLocation.getStatus()==null){
customerLocationList.add(customerLocation);
}
}
}捕获(例外e){
log.error(“[{}]从elastic获取客户位置时发生异常”,genericRequest.getClientNo(),e);
}
返回customerLocationList;
}
我在运行上述代码时遇到了以下异常。我怎么了

org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]
    at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177) ~[elasticsearch-7.5.2.jar:7.5.2]
    at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:1793) ~[elasticsearch-rest-high-level-client-7.5.2.jar:7.5.2]
    at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:1770) ~[elasticsearch-rest-high-level-client-7.5.2.jar:7.5.2]
    at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1527) ~[elasticsearch-rest-high-level-client-7.5.2.jar:7.5.2]
    at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1484) ~[elasticsearch-rest-high-level-client-7.5.2.jar:7.5.2]
    at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1454) ~[elasticsearch-rest-high-level-client-7.5.2.jar:7.5.2]
    at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:970) ~[elasticsearch-rest-high-level-client-7.5.2.jar:7.5.2]
    at com.ykb.frd.fraudlocation.elastic.repository.CustomerLocationRepositoryImpl.findByCifNoAndUserIdWithinLocation(CustomerLocationRepositoryImpl.java:61) ~[classes/:na]
    at com.ykb.frd.fraudlocation.elastic.repository.CustomerLocationRepositoryImpl$$FastClassBySpringCGLIB$$8bf452.invoke(<generated>) [classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) [spring-core-5.2.1.RELEASE.jar:5.2.1.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:769) [spring-aop-5.2.1.RELEASE.jar:5.2.1.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.2.1.RELEASE.jar:5.2.1.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747) [spring-aop-5.2.1.RELEASE.jar:5.2.1.RELEASE]
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) [spring-tx-5.2.1.RELEASE.jar:5.2.1.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.2.1.RELEASE.jar:5.2.1.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747) [spring-aop-5.2.1.RELEASE.jar:5.2.1.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) [spring-aop-5.2.1.RELEASE.jar:5.2.1.RELEASE]
    at com.ykb.frd.fraudlocation.elastic.repository.CustomerLocationRepositoryImpl$$EnhancerBySpringCGLIB$$ad3f68fd.findByCifNoAndUserIdWithinLocation(<generated>) [classes/:na]
    at com.ykb.frd.fraudlocation.elastic.ElasticServiceImpl.getCustomersLocationsIndexWithinLocation(ElasticServiceImpl.java:30) [classes/:na]
    at com.ykb.frd.fraudlocation.ElasticTest.elasticDataLocationFoundTest(ElasticTest.java:44) [test-classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) [junit-4.12.jar:4.12]
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12.jar:4.12]
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) [junit-4.12.jar:4.12]
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) [junit-4.12.jar:4.12]
org.elasticsearch.ElasticsearchStatusException:elasticsearch异常[type=search\u phase\u execution\u exception,reason=all shard failed]
在org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177)~[elasticsearch-7.5.2.jar:7.5.2]
在org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:1793)~[elasticsearch-rest-high-level-client-7.5.2.jar:7.5.2]
在org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:1770)~[elasticsearch-rest-high-level-client-7.5.2.jar:7.5.2]
在org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1527)~[elasticsearch-rest-high-level-client-7.5.2.jar:7.5.2]
在org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1484)~[elasticsearch-rest-high-level-client-7.5.2.jar:7.5.2]
在org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1454)~[elasticsearch-rest-high-level-client-7.5.2.jar:7.5.2]
在org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:970)~[elasticsearch-rest-high-level-client-7.5.2.jar:7.5.2]
在com.ykb.frd.fraudlocation.elastic.repository.CustomerLocationRepositoryImpl.findByCifNoAndUserIdWithinLocation(CustomerLocationRepositoryImpl.java:61)~[classes/:na]
在com.ykb.frd.fraudlocation.elastic.repository.CustomerLocationRepositoryImpl$$FastClassBySpringCGLIB$$8bf452.invoke()[classes/:na]
在org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)[spring-core-5.2.1.RELEASE.jar:5.2.1.RELEASE]
位于org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:769)[spring-aop-5.2.1.RELEASE.jar:5.2.1.RELEASE]
在org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:163)[spring-aop-5.2.1.RELEASE.jar:5.2.1.RELEASE]
在org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.procedue(CglibAopProxy.java:747)[spring-aop-5.2.1.RELEASE.jar:5.2.1.RELEASE]
位于org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)[spring-tx-5.2.1.RELEASE.jar:5.2.1.RELEASE]
在org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:186)[spring-aop-5.2.1.RELEASE.jar:5.2.1.RELEASE]
在org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.procedue(CglibAopProxy.java:747)[spring-aop-5.2.1.RELEASE.jar:5.2.1.RELEASE]
在org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)[spring-aop-5.2.1.RELEASE.jar:5.2.1.RELEASE]
在com.ykb.frd.fraudlocation.elastic.repository.CustomerLocationRepositoryImpl$$EnhancerBySpringCGLIB$$ad3f68fd.findByCifNoAndUserIdWithinLocation()[classes/:na]
在com.ykb.frd.fraudlocation.elastic.ElasticServiceImpl.GetCustomerLocationsIndexWithInLocation(ElasticServiceImpl.java:30)[classes/:na]
在com.ykb.frd.fraudlocation.ElasticTest.elasticDataLocationFoundTest(ElasticTest.java:44)[测试类/:na]
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)~[na:1.8.0_65]
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)~[na:1.8.0\u 65]
在太阳下
...
{
  "geoPoint":{
    "properties":{

      ...

      "lat":{
        "type":"float"
      },
      "lon":{
        "type":"float"
      },

      "as_geopoint": {         <-----
        "type": "geo_point"
      }
    }
  }
}
...
{
  ...
  "geoPoint": {
    ...
    "as_geopoint": {
       "lat": 41.12,
       "lon": -71.34
    }
  }
}