Я делаю веб-сервис с пружинной загрузкой и asticsearch, чтобы получить пользователей в определенном диапазоне

Итак, я использую GeoDistanceQueryBuilder, чтобы получить пользователей в пределах определенного диапазона, и когда я запускаю приложение, возникает следующая ошибка:

org.elasticsearch.index.query.QueryParsingException: failed to find geo_point field [location]
at org.elasticsearch.index.query.GeoDistanceQueryParser.parse(GeoDistanceQueryParser.java:175) ~[elasticsearch-2.4.0.jar:2.4.0]
at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:250) ~[elasticsearch-2.4.0.jar:2.4.0]
at org.elasticsearch.index.query.IndexQueryParserService.innerParse(IndexQueryParserService.java:320) ~[elasticsearch-2.4.0.jar:2.4.0]
at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:223) ~[elasticsearch-2.4.0.jar:2.4.0]
at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:218) ~[elasticsearch-2.4.0.jar:2.4.0]
at org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:33) ~[elasticsearch-2.4.0.jar:2.4.0]
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:856) ~[elasticsearch-2.4.0.jar:2.4.0]
at org.elasticsearch.search.SearchService.createContext(SearchService.java:667) ~[elasticsearch-2.4.0.jar:2.4.0]
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:633) ~[elasticsearch-2.4.0.jar:2.4.0]
at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:472) ~[elasticsearch-2.4.0.jar:2.4.0]
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryFetchTransportHandler.messageReceived(SearchServiceTransportAction.java:392) ~[elasticsearch-2.4.0.jar:2.4.0]
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryFetchTransportHandler.messageReceived(SearchServiceTransportAction.java:389) ~[elasticsearch-2.4.0.jar:2.4.0]
at org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:33) ~[elasticsearch-2.4.0.jar:2.4.0]
at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:77) ~[elasticsearch-2.4.0.jar:2.4.0]
at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:376) ~[elasticsearch-2.4.0.jar:2.4.0]
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-2.4.0.jar:2.4.0]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_131]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_131]

это класс Users, который я сопоставил с asticsearch:

int id;

String first_name, last_name, city, country, email, profession, gender;
String facebook_profile, google_profile, twitter_profile, photo, photo_UUID;

GeoPoint location;

public Users() {
    super();
}

public Users(int id, String first_name, String last_name, String city, String country, String email,
        String profession, String gender, String facebook_profile, String google_profile, String twitter_profile,
        String photo, String photo_UUID, GeoPoint location) {
    super();
    this.id = id;
    this.first_name = first_name;
    this.last_name = last_name;
    this.city = city;
    this.country = country;
    this.email = email;
    this.profession = profession;
    this.gender = gender;
    this.facebook_profile = facebook_profile;
    this.google_profile = google_profile;
    this.twitter_profile = twitter_profile;
    this.photo = photo;
    this.photo_UUID = photo_UUID;
    this.location = location;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getFirst_name() {
    return first_name;
}

public void setFirst_name(String first_name) {
    this.first_name = first_name;
}

public String getLast_name() {
    return last_name;
}

public void setLast_name(String last_name) {
    this.last_name = last_name;
}

public String getCity() {
    return city;
}

public void setCity(String city) {
    this.city = city;
}

public String getCountry() {
    return country;
}

public void setCountry(String country) {
    this.country = country;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getProfession() {
    return profession;
}

public void setProfession(String profession) {
    this.profession = profession;
}

public String getGender() {
    return gender;
}

public void setGender(String gender) {
    this.gender = gender;
}

public String getFacebook_profile() {
    return facebook_profile;
}

public void setFacebook_profile(String facebook_profile) {
    this.facebook_profile = facebook_profile;
}

public String getGoogle_profile() {
    return google_profile;
}

public void setGoogle_profile(String google_profile) {
    this.google_profile = google_profile;
}

public String getTwitter_profile() {
    return twitter_profile;
}

public void setTwitter_profile(String twitter_profile) {
    this.twitter_profile = twitter_profile;
}

public String getPhoto() {
    return photo;
}

public void setPhoto(String photo) {
    this.photo = photo;
}

public String getPhoto_UUID() {
    return photo_UUID;
}

public void setPhoto_UUID(String photo_UUID) {
    this.photo_UUID = photo_UUID;
}

public GeoPoint getLocation() {
    return location;
}

public void setLocation(GeoPoint location) {
    this.location = location;
}

и этот класс, который загружает данные:

    @Autowired
ElasticsearchTemplate operations;

@Autowired
UsersRepository usersRepository;

@PostConstruct
@Transactional
public void loadAll(){

    operations.createIndex(Users.class);
    operations.putMapping(Users.class);
    System.out.println("Loading Data");
    usersRepository.save(getData());
    System.out.println("Loading Completed");

}

private List<Users> getData() {

    List<Users> users_list = new ArrayList<>();        

    users_list.add(new Users(1, "A", "A", "cairo", "egypt", "A@gmail.com", "software engineer", "male", 
                            "fb.com/AA", "google.com/AA", "@A", "54552222", "54552222", new GeoPoint(14.2, 12.5)));

    users_list.add(new Users(2, "B", "B", "aswan", "egypt", "B@gmail.com", "software engineer", "male", 
                             "fb.com/BB", "google.com/BB", "@B", "54552222", "54552222", new GeoPoint(14.2, 25.5)));

    users_list.add(new Users(3, "C", "C", "luxor", "egypt", "C@gmail.com", "software engineer", "male", 
                             "fb.com/CC", "google.com/CC", "@C", "54552222", "54552222", new GeoPoint(34.4, 22.5)));

    users_list.add(new Users(4, "D", "D", "cairo", "egypt", "D@gmail.com", "software engineer", "male", 
                             "fb.com/DD", "google.com/DD", "@D", "54552222", "54552222", new GeoPoint(14.2, 12.5)));

    users_list.add(new Users(5, "E", "E", "cairo", "egypt", "E@gmail.com", "software engineer", "male", 
                            "fb.com/EE", "google.com/EE", "@E", "54552222", "54552222", new GeoPoint(14.1, 12.5)));

    users_list.add(new Users(6, "F", "F", "aswan", "egypt", "F@gmail.com", "software engineer", "male", 
                             "fb.com/FF", "google.com/FF", "@F", "54552222", "54552222", new GeoPoint(14.2, 25.5)));

    users_list.add(new Users(7, "G", "G", "luxor", "egypt", "G@gmail.com", "software engineer", "male", 
                             "fb.com/GG", "google.com/GG", "@G", "54552222", "54552222", new GeoPoint(34.4, 22.5)));

    users_list.add(new Users(8, "H", "H", "cairo", "egypt", "H@gmail.com", "software engineer", "male", 
                             "fb.com/HH", "google.com/HH", "@H", "54552222", "54552222", new GeoPoint(14.7, 12.2)));

    users_list.add(new Users(9, "I", "I", "cairo", "egypt", "I@gmail.com", "software engineer", "male", 
                             "fb.com/II", "google.com/II", "@I", "54552222", "54552222", new GeoPoint(15.2, 13.5)));

    users_list.add(new Users(10, "J", "J", "aswan", "egypt", "J@gmail.com", "software engineer", "male", 
                             "fb.com/JJ", "google.com/JJ", "@J", "54552222", "54552222", new GeoPoint(11.4, 25.1)));

    users_list.add(new Users(11, "K", "K", "aswan", "egypt", "K@gmail.com", "software engineer", "male", 
                             "fb.com/KK", "google.com/KK", "@K", "54552222", "54552222", new GeoPoint(11.4, 25.1)));

    users_list.add(new Users(12, "L", "L", "aswan", "egypt", "L@gmail.com", "software engineer", "male", 
                             "fb.com/LL", "google.com/JJ", "@L", "54552222", "54552222", new GeoPoint(11.4, 25.1)));
    return users_list;
}

и это запрос, который должен получить пользователей в заданном диапазоне:

@RequestMapping(value = "/range/{Longitude}/{Latitude}/{Range}", method = RequestMethod.GET)
public List<Users> searchGPS(@PathVariable double Longitude,
        @PathVariable double Latitude, @PathVariable int Range) throws Exception {

     GeoDistanceQueryBuilder query = QueryBuilders.geoDistanceQuery("location").point(Latitude, Longitude)
                    .distance(Range, DistanceUnit.KILOMETERS).optimizeBbox("memory")
                    .geoDistance(GeoDistance.SLOPPY_ARC);

      NativeSearchQuery build = new NativeSearchQueryBuilder()
                .withQuery(query)   
                .build();


    List<Users> users_within_range = new ArrayList<>();

    users_within_range = elasticsearchTemplate.queryForList(build, Users.class);

    return users_within_range;


}

Кроме того, эта ошибка выскакивает в консолиручение

Кто-нибудь может помочь, кстати, я использую эластичный поиск 2.4.0?!

0 ответов

Другие вопросы по тегам