32
32
import org .elasticsearch .test .ElasticsearchIntegrationTest ;
33
33
import org .junit .Test ;
34
34
35
- import java .util .ArrayList ;
36
- import java .util .List ;
37
- import java .util .Random ;
35
+ import java .util .*;
38
36
39
37
import static org .elasticsearch .common .xcontent .XContentFactory .jsonBuilder ;
40
38
import static org .elasticsearch .search .aggregations .AggregationBuilders .geohashGrid ;
46
44
@ ElasticsearchIntegrationTest .SuiteScopeTest
47
45
public class GeoHashGridTests extends ElasticsearchIntegrationTest {
48
46
49
- private IndexRequestBuilder indexCity (String name , String latLon ) throws Exception {
47
+ private IndexRequestBuilder indexCity (String index , String name , List < String > latLon ) throws Exception {
50
48
XContentBuilder source = jsonBuilder ().startObject ().field ("city" , name );
51
49
if (latLon != null ) {
52
50
source = source .field ("location" , latLon );
53
51
}
54
52
source = source .endObject ();
55
- return client ().prepareIndex ("idx" , "type" ).setSource (source );
53
+ return client ().prepareIndex (index , "type" ).setSource (source );
56
54
}
57
55
58
56
59
57
static ObjectIntMap <String > expectedDocCountsForGeoHash = null ;
58
+ static ObjectIntMap <String > multiValuedExpectedDocCountsForGeoHash = null ;
60
59
static int highestPrecisionGeohash = 12 ;
61
60
static int numRandomPoints = 100 ;
62
61
@@ -78,7 +77,7 @@ public void setupSuiteScopeCluster() throws Exception {
78
77
double lng = (360d * random .nextDouble ()) - 180d ;
79
78
String randomGeoHash = GeoHashUtils .encode (lat , lng , highestPrecisionGeohash );
80
79
//Index at the highest resolution
81
- cities .add (indexCity (randomGeoHash , lat + ", " + lng ));
80
+ cities .add (indexCity ("idx" , randomGeoHash , Collections . singletonList ( lat + ", " + lng ) ));
82
81
expectedDocCountsForGeoHash .put (randomGeoHash , expectedDocCountsForGeoHash .getOrDefault (randomGeoHash , 0 ) + 1 );
83
82
//Update expected doc counts for all resolutions..
84
83
for (int precision = highestPrecisionGeohash - 1 ; precision > 0 ; precision --) {
@@ -90,6 +89,33 @@ public void setupSuiteScopeCluster() throws Exception {
90
89
}
91
90
}
92
91
indexRandom (true , cities );
92
+
93
+ assertAcked (prepareCreate ("multi_valued_idx" )
94
+ .addMapping ("type" , "location" , "type=geo_point" , "city" , "type=string,index=not_analyzed" ));
95
+
96
+ cities = new ArrayList <>();
97
+ multiValuedExpectedDocCountsForGeoHash = new ObjectIntOpenHashMap <>(numRandomPoints * 2 );
98
+ for (int i = 0 ; i < numRandomPoints ; i ++) {
99
+ final int numPoints = random .nextInt (4 );
100
+ List <String > points = new ArrayList <>();
101
+ Set <String > geoHashes = new HashSet <>();
102
+ for (int j = 0 ; j < numPoints ; ++j ) {
103
+ double lat = (180d * random .nextDouble ()) - 90d ;
104
+ double lng = (360d * random .nextDouble ()) - 180d ;
105
+ points .add (lat + "," + lng );
106
+ // Update expected doc counts for all resolutions..
107
+ for (int precision = highestPrecisionGeohash ; precision > 0 ; precision --) {
108
+ final String geoHash = GeoHashUtils .encode (lat , lng , precision );
109
+ geoHashes .add (geoHash );
110
+ }
111
+ }
112
+ cities .add (indexCity ("multi_valued_idx" , Integer .toString (i ), points ));
113
+ for (String hash : geoHashes ) {
114
+ multiValuedExpectedDocCountsForGeoHash .put (hash , multiValuedExpectedDocCountsForGeoHash .getOrDefault (hash , 0 ) + 1 );
115
+ }
116
+ }
117
+ indexRandom (true , cities );
118
+
93
119
ensureSearchable ();
94
120
}
95
121
0 commit comments