- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个用于使用elasticsearch geopoint 的Spring Boot 应用程序。当我保存弹性索引并创建 geoDistanceQuery 时,我收到 QueryShardException[failed to find geo_point field [customer]] 异常。
我的文档;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.GeoPointField;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Getter
@Setter
@Document(indexName = "customer", replicas = 0, refreshInterval = "-1")
public class Customer {
@GeneratedValue(strategy= GenerationType.AUTO)
@Id
private String id;
private Integer cifNo;
private String userId;
private String name;
@GeoPointField
private GeoPoint geoPoint;
}
存储库;
@Repository
public interface CustomerRepository extends ElasticsearchRepository<Customer, String> { }
保存和获取方法;
import com.system.management.domain.entity.Customer;
import com.system.management.repository.CustomerRepository;
import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.index.query.GeoDistanceQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class LocationFinder {
@Autowired
public ElasticsearchOperations elasticsearchTemplate;
@Autowired
public CustomerRepository customerRepository;
public void saveNewLocation(Customer customer) {
customerRepository.save(customer);
}
public List<Customer> getLocationMembers(){
GeoDistanceQueryBuilder geoDistanceQueryBuilder = QueryBuilders
.geoDistanceQuery("customer")
.point(29.976, 31.131)
.distance(10, DistanceUnit.KILOMETERS);
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withFilter(geoDistanceQueryBuilder)
.build();
return elasticsearchTemplate.queryForList(searchQuery,Customer.class);
}
}
测试方法;
@Test
public void testLocation() {
Customer customer = new Customer();
customer.setName("base");
customer.setCifNo(1242343);
customer.setGeoPoint(new GeoPoint(29.876, 31.231));
locationFinder.saveNewLocation(customer);
List<Customer> customerList = locationFinder.getLocationMembers();
Assert.assertNotEquals(0,customerList.size());
}
异常跟踪;
Failed to execute phase [dfs], all shards failed
; shardFailures {[v4sPjgozTueAfeXoU4Ua5w][customer][0]: RemoteTransportException[[mertaksu-MBP][127.0.0.1:9300][indices:data/read/search[phase/dfs]]]; nested: QueryShardException[failed to find geo_point field [customer]]; }{[v4sPjgozTueAfeXoU4Ua5w][customer][1]: RemoteTransportException[[mertaksu-MBP][127.0.0.1:9300][indices:data/read/search[phase/dfs]]]; nested: QueryShardException[failed to find geo_point field [customer]]; }{[v4sPjgozTueAfeXoU4Ua5w][customer][2]: RemoteTransportException[[mertaksu-MBP][127.0.0.1:9300][indices:data/read/search[phase/dfs]]]; nested: QueryShardException[failed to find geo_point field [customer]]; }{[v4sPjgozTueAfeXoU4Ua5w][customer][3]: RemoteTransportException[[mertaksu-MBP][127.0.0.1:9300][indices:data/read/search[phase/dfs]]]; nested: QueryShardException[failed to find geo_point field [customer]]; }{[v4sPjgozTueAfeXoU4Ua5w][customer][4]: RemoteTransportException[[mertaksu-MBP][127.0.0.1:9300][indices:data/read/search[phase/dfs]]]; nested: QueryShardException[failed to find geo_point field [customer]]; }
at org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:534)
at org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:305)
at org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseDone(AbstractSearchAsyncAction.java:563)
at org.elasticsearch.action.search.AbstractSearchAsyncAction.onShardFailure(AbstractSearchAsyncAction.java:384)
at org.elasticsearch.action.search.AbstractSearchAsyncAction.access$200(AbstractSearchAsyncAction.java:65)
at org.elasticsearch.action.search.AbstractSearchAsyncAction$1.onFailure(AbstractSearchAsyncAction.java:241)
at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:59)
at org.elasticsearch.action.search.SearchTransportService$ConnectionCountingHandler.handleException(SearchTransportService.java:423)
at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:1120)
at org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:1229)
at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1203)
at org.elasticsearch.transport.TaskTransportChannel.sendResponse(TaskTransportChannel.java:60)
at org.elasticsearch.action.search.SearchTransportService$2.onFailure(SearchTransportService.java:323)
at org.elasticsearch.action.ActionListener$1.onFailure(ActionListener.java:71)
at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:65)
at org.elasticsearch.action.ActionRunnable.lambda$supply$0(ActionRunnable.java:58)
at org.elasticsearch.action.ActionRunnable$2.doRun(ActionRunnable.java:73)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:44)
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:773)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.lang.Thread.run(Thread.java:830)
Caused by: [customer/fSg6OP_fT0OIG4JAiUFhgA] QueryShardException[failed to find geo_point field [customer]]
at org.elasticsearch.index.query.GeoDistanceQueryBuilder.doToQuery(GeoDistanceQueryBuilder.java:235)
at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:99)
at org.elasticsearch.index.query.QueryShardContext.lambda$toQuery$1(QueryShardContext.java:331)
at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:343)
at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:330)
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:749)
at org.elasticsearch.search.SearchService.createContext(SearchService.java:586)
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:545)
at org.elasticsearch.search.SearchService.executeDfsPhase(SearchService.java:309)
at org.elasticsearch.search.SearchService.lambda$executeDfsPhase$0(SearchService.java:305)
at org.elasticsearch.action.ActionListener.lambda$map$2(ActionListener.java:146)
at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:63)
我的 Elastic 版本; 7.5.1Spring数据弹性版;
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
当我得到http://localhost:9200/customer/_mapping时网址;
{"customer":{"mappings":{"properties":{"cifNo":{"type":"long"},"geoPoint":{"type":"geo_point"},"name":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}}}
我该如何解决这个问题?
最佳答案
必须使用字段名称构建地理点查询:
GeoDistanceQueryBuilder geoDistanceQueryBuilder = QueryBuilders
.geoDistanceQuery("geoPoint")
.point(29.976, 31.131)
.distance(10, DistanceUnit.KILOMETERS);
顺便说一句,如果您的属性是 GeoPoint
类型,则不需要 @GeoPointField
注释,它会映射到 geo_point(如果有)该类是 GeoPoint
或存在注释。
关于java - Spring Data Elasticsearch 找不到 geo_point 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59619410/
我正在尝试在 Windows 上运行的小于 1GB 的 VM 上设置 YouTrack 和 TeamCity。使用率将非常低(用户和请求)。这是一个 POC 环境,如果它有效,我可能会将它推送到一个超
所以我在尝试使用 FORFILES 解决这个问题时遇到了麻烦。我正在尝试获取不超过 4 天的文件。所以基本上少于 4 天。然而,这似乎不太可能,因为/d -4 获取所有 4 天或更早的项目。 以下是我
如何从下面的 events 表中选择小于 15 分钟前创建的 events? CREATE TABLE events ( created_at timestamp NOT NULL DEFAU
Google Analytics Realtime提供 rt:minutesAgo ,可以过滤查询。 然而,它是一个维度而不是一个度量标准,<=不能在过滤器中使用。 假设我想在最后 n 分钟内获得一些
iOS 核心数据 - 严重的应用程序错误 - 尝试插入 nil 你好, 我的应用程序实际上运行稳定,但在极少数情况下它会崩溃并显示此错误消息... 2019-04-02 20:48:52.437172
我想制作一个 html div 以快速向右移动(例如不到 1 秒)并消失。然后1秒后再次直接出现在这个过程最开始div的位置。此过程将由单击按钮并重复 10 次触发。 我试图在 CSS 中使用过渡属性
我发现使用 TimeTrigger 是 Windows 10 (UWP) 上计划后台任务的方式。但是看起来我们需要给出的最小数字是 15 分钟。只是想知道,即使我们安排它在接下来的 1 分钟内运行,警
我必须在 1 秒内在屏幕上打印 2^20 行整数 printf 不够快,还有其他易于使用的快速输出替代方法吗? 每一行只包含 1 个整数。 我要求它用于竞争性编程问题,我必须将其源代码提交给法官。 最
我是一名优秀的程序员,十分优秀!