Skip to content

Commit aabed86

Browse files
committed
Merge branch 'master' into 6.2
2 parents 19281d0 + 70e0742 commit aabed86

File tree

6 files changed

+180
-126
lines changed

6 files changed

+180
-126
lines changed

README.md

Lines changed: 57 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This is a multi bucket aggregation.
1111
Installation
1212
------------
1313

14-
`bin/plugin --install path_hierarchy --url "https://github.com/opendatasoft/elasticsearch-aggregation-pathhierarchy/releases/download/v6.4.2.0/elasticsearch-aggregation-pathhierarchy-6.4.2.0.zip"`
14+
`bin/plugin --install path_hierarchy --url "https://github.com/opendatasoft/elasticsearch-aggregation-pathhierarchy/releases/download/v6.4.2.1/elasticsearch-aggregation-pathhierarchy-6.4.2.1.zip"`
1515

1616

1717
Usage
@@ -27,6 +27,7 @@ Usage
2727
- `min_depth`: Set minimum depth level. Default to 0.
2828
- `max_depth`: Set maximum depth level. `-1` means no limit. Default to 3.
2929
- `depth`: Retrieve values for specified depth. Shortcut, instead of setting `min_depth` and `max_depth` parameters to the same value.
30+
- `two_sep_as_one`: Will consider two separator which follow each other as one. For example with separator `/`, `/root/my_dir` will be equivalent to `/root//my_dir` if set to true, else it will be equivalent to `/root/empty/my_dir`. Default to true.
3031

3132
Please note that `sum_other_doc_count` is returned alongside aggregation buckets. It returns the sum of doc_count which are not returned from shards due to size/shard_size and so can be used to calibrate size/shard_size.
3233

@@ -72,12 +73,6 @@ PUT /filesystem/file/3
7273
"views": 1
7374
}
7475
75-
PUT /filesystem/file/4
76-
{
77-
"path": "/My documents/Spreadsheets/Budget_2014.xls",
78-
"views": 12
79-
}
80-
8176
8277
8378
Path hierarchy request :
@@ -88,10 +83,7 @@ GET /filesystem/file/_search?size=0
8883
"tree": {
8984
"path_hierarchy": {
9085
"field": "path",
91-
"separator": "/",
92-
"order": [{"_count": "desc"}, {"_key": "asc"}],
93-
"min_depth": 0,
94-
"max_depth": 3
86+
"separator": "/"
9587
},
9688
"aggs": {
9789
"total_views": {
@@ -108,54 +100,54 @@ GET /filesystem/file/_search?size=0
108100
Result :
109101
110102
{"aggregations": {
111-
"tree": {
112-
"buckets": [
113-
{
114-
"key": "My documents",
115-
"doc_count": 4,
116-
"total_views": {
117-
"value": 30
118-
},
119-
"tree": {
120-
"buckets": [
121-
{
122-
"key": "Spreadsheets",
123-
"doc_count": 3,
124-
"total_views": {
125-
"value": 29
126-
},
127-
"tree": {
128-
"buckets": [
129-
{
130-
"key": "Budget_2014.xls",
131-
"doc_count": 2,
132-
"total_views": {
133-
"value": 19
134-
}
135-
},
136-
{
137-
"key": "Budget_2013.xls",
138-
"doc_count": 1,
139-
"total_views": {
140-
"value": 10
141-
}
142-
}
143-
]
144-
}
145-
},
146-
{
147-
"key": "Test.txt",
148-
"doc_count": 1,
149-
"total_views": {
150-
"value": 1
151-
}
152-
}
153-
]
154-
}
155-
}
156-
]
157-
}
158-
}
103+
"tree": {
104+
"sum_other_doc_count": 0,
105+
"buckets": [
106+
{
107+
"key": "My documents",
108+
"doc_count": 3,
109+
"total_views": {
110+
"value": 18
111+
},
112+
"tree": {
113+
"buckets": [
114+
{
115+
"key": "Spreadsheets",
116+
"doc_count": 2,
117+
"total_views": {
118+
"value": 17
119+
},
120+
"tree": {
121+
"buckets": [
122+
{
123+
"key": "Budget_2013.xls",
124+
"doc_count": 1,
125+
"total_views": {
126+
"value": 10
127+
}
128+
},
129+
{
130+
"key": "Budget_2014.xls",
131+
"doc_count": 1,
132+
"total_views": {
133+
"value": 7
134+
}
135+
}
136+
]
137+
}
138+
},
139+
{
140+
"key": "Test.txt",
141+
"doc_count": 1,
142+
"total_views": {
143+
"value": 1
144+
}
145+
}
146+
]
147+
}
148+
}
149+
]
150+
}
159151
}
160152
161153
```
@@ -264,16 +256,16 @@ Plugin versions are available for (at least) all minor versions of Elasticsearch
264256
The first 3 digits of plugin version is Elasticsearch versioning. The last digit is used for plugin versioning under an elasticsearch version.
265257

266258
To install it, launch this command in Elasticsearch directory replacing the url by the correct link for your Elasticsearch version (see table)
267-
`./bin/elasticsearch-plugin install https://github.com/opendatasoft/elasticsearch-aggregation-pathhierarchy/releases/download/v6.4.1.0/elasticsearch-aggregation-pathhierarchy-6.4.1.0.zip`
259+
`./bin/elasticsearch-plugin install https://github.com/opendatasoft/elasticsearch-aggregation-pathhierarchy/releases/download/v6.4.1.1/elasticsearch-aggregation-pathhierarchy-6.4.1.1.zip`
268260

269261
| elasticsearch version | plugin version | plugin url |
270262
| --------------------- | -------------- | ---------- |
271263
| 1.6.0 | 1.6.0.4 | https://github.com/opendatasoft/elasticsearch-aggregation-pathhierarchy/releases/download/v1.6.0.4/elasticsearch-aggregation-pathhierarchy-1.6.0.4.zip |
272-
| 6.0.1 | 6.0.1.0 | https://github.com/opendatasoft/elasticsearch-aggregation-pathhierarchy/releases/download/v6.0.1.0/elasticsearch-aggregation-pathhierarchy-6.0.1.0.zip |
273-
| 6.1.4 | 6.1.4.0 | https://github.com/opendatasoft/elasticsearch-aggregation-pathhierarchy/releases/download/v6.1.4.0/elasticsearch-aggregation-pathhierarchy-6.1.4.0.zip |
274-
| 6.2.4 | 6.2.4.0 | https://github.com/opendatasoft/elasticsearch-aggregation-pathhierarchy/releases/download/v6.2.4.0/elasticsearch-aggregation-pathhierarchy-6.2.4.0.zip |
275-
| 6.3.2 | 6.3.2.0 | https://github.com/opendatasoft/elasticsearch-aggregation-pathhierarchy/releases/download/v6.3.2.0/elasticsearch-aggregation-pathhierarchy-6.3.2.0.zip |
276-
| 6.4.2 | 6.4.2.0 | https://github.com/opendatasoft/elasticsearch-aggregation-pathhierarchy/releases/download/v6.4.2.0/elasticsearch-aggregation-pathhierarchy-6.4.2.0.zip |
264+
| 6.0.1 | 6.0.1.1 | https://github.com/opendatasoft/elasticsearch-aggregation-pathhierarchy/releases/download/v6.0.1.1/elasticsearch-aggregation-pathhierarchy-6.0.1.1.zip |
265+
| 6.1.4 | 6.1.4.1 | https://github.com/opendatasoft/elasticsearch-aggregation-pathhierarchy/releases/download/v6.1.4.1/elasticsearch-aggregation-pathhierarchy-6.1.4.1.zip |
266+
| 6.2.4 | 6.2.4.1 | https://github.com/opendatasoft/elasticsearch-aggregation-pathhierarchy/releases/download/v6.2.4.1/elasticsearch-aggregation-pathhierarchy-6.2.4.1.zip |
267+
| 6.3.2 | 6.3.2.1 | https://github.com/opendatasoft/elasticsearch-aggregation-pathhierarchy/releases/download/v6.3.2.1/elasticsearch-aggregation-pathhierarchy-6.3.2.1.zip |
268+
| 6.4.2 | 6.4.2.1 | https://github.com/opendatasoft/elasticsearch-aggregation-pathhierarchy/releases/download/v6.4.2.1/elasticsearch-aggregation-pathhierarchy-6.4.2.1.zip |
277269

278270

279271
License

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
elasticVersion = 6.2.4
2-
pluginVersion = 6.2.4.0
2+
pluginVersion = 6.2.4.1
3+

src/main/java/org/opendatasoft/elasticsearch/search/aggregations/bucket/PathHierarchyAggregationBuilder.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class PathHierarchyAggregationBuilder extends ValuesSourceAggregationBuil
3838
public static final ParseField SEPARATOR_FIELD = new ParseField("separator");
3939
public static final ParseField MIN_DEPTH_FIELD = new ParseField("min_depth");
4040
public static final ParseField MAX_DEPTH_FIELD = new ParseField("max_depth");
41+
public static final ParseField TWO_SEP_AS_ONE_FIELD = new ParseField("two_sep_as_one");
4142
public static final ParseField DEPTH_FIELD = new ParseField("depth");
4243
public static final ParseField ORDER_FIELD = new ParseField("order");
4344
public static final ParseField SIZE_FIELD = new ParseField("size");
@@ -53,6 +54,7 @@ public class PathHierarchyAggregationBuilder extends ValuesSourceAggregationBuil
5354
PARSER.declareString(PathHierarchyAggregationBuilder::separator, SEPARATOR_FIELD);
5455
PARSER.declareInt(PathHierarchyAggregationBuilder::minDepth, MIN_DEPTH_FIELD);
5556
PARSER.declareInt(PathHierarchyAggregationBuilder::maxDepth, MAX_DEPTH_FIELD);
57+
PARSER.declareBoolean(PathHierarchyAggregationBuilder::twoSepAsOne, TWO_SEP_AS_ONE_FIELD);
5658
PARSER.declareInt(PathHierarchyAggregationBuilder::depth, DEPTH_FIELD);
5759
PARSER.declareInt(PathHierarchyAggregationBuilder::size, SIZE_FIELD);
5860
PARSER.declareInt(PathHierarchyAggregationBuilder::shardSize, SHARD_SIZE_FIELD);
@@ -67,9 +69,11 @@ public static AggregationBuilder parse(String aggregationName, XContentParser pa
6769
private static final String DEFAULT_SEPARATOR = "/";
6870
private static final int DEFAULT_MIN_DEPTH = 0;
6971
private static final int DEFAULT_MAX_DEPTH = 3;
72+
private static final boolean DEFAULT_TWO_SEP_AS_ONE = true;
7073
private String separator = DEFAULT_SEPARATOR;
7174
private int minDepth = DEFAULT_MIN_DEPTH;
7275
private int maxDepth = DEFAULT_MAX_DEPTH;
76+
private boolean twoSepAsOne = DEFAULT_TWO_SEP_AS_ONE;
7377
private int depth = -1;
7478
private BucketOrder order = BucketOrder.compound(BucketOrder.count(false)); // automatically adds tie-breaker key asc order
7579
private PathHierarchyAggregator.BucketCountThresholds bucketCountThresholds = new PathHierarchyAggregator.BucketCountThresholds(
@@ -90,6 +94,7 @@ public PathHierarchyAggregationBuilder(StreamInput in) throws IOException {
9094
separator = in.readString();
9195
minDepth = in.readOptionalVInt();
9296
maxDepth = in.readOptionalVInt();
97+
twoSepAsOne = in.readOptionalBoolean();
9398
depth = in.readOptionalVInt();
9499
order = InternalOrder.Streams.readOrder(in);
95100
}
@@ -103,6 +108,7 @@ protected void innerWriteTo(StreamOutput out) throws IOException {
103108
out.writeString(separator);
104109
out.writeOptionalVInt(minDepth);
105110
out.writeOptionalVInt(maxDepth);
111+
out.writeOptionalBoolean(twoSepAsOne);
106112
out.writeOptionalVInt(depth);
107113
order.writeTo(out);
108114
}
@@ -122,6 +128,11 @@ private PathHierarchyAggregationBuilder maxDepth(int maxDepth) {
122128
return this;
123129
}
124130

131+
private PathHierarchyAggregationBuilder twoSepAsOne(boolean twoSepAsOne) {
132+
this.twoSepAsOne = twoSepAsOne;
133+
return this;
134+
}
135+
125136
private PathHierarchyAggregationBuilder depth(int depth) {
126137
this.depth = depth;
127138
return this;
@@ -213,7 +224,7 @@ public int shardSize() {
213224
}
214225

215226
return new PathHierarchyAggregatorFactory(
216-
name, config, separator, minDepth, maxDepth, order, bucketCountThresholds,
227+
name, config, separator, minDepth, maxDepth, twoSepAsOne, order, bucketCountThresholds,
217228
context, parent, subFactoriesBuilder, metaData);
218229
}
219230

src/main/java/org/opendatasoft/elasticsearch/search/aggregations/bucket/PathHierarchyAggregator.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -190,24 +190,6 @@ public void collect(int doc, long owningBucketOrdinal) throws IOException {
190190
public InternalAggregation buildAggregation(long owningBucketOrdinal) throws IOException {
191191
assert owningBucketOrdinal == 0;
192192

193-
// get back buckets
194-
if (!InternalOrder.isCountDesc(order) || (bucketOrds.size() < bucketCountThresholds.getRequiredSize())) {
195-
// we need to fill-in the blanks
196-
for (LeafReaderContext ctx : context.searcher().getTopReaderContext().leaves()) {
197-
final SortedBinaryDocValues values = valuesSource.bytesValues(ctx);
198-
// brute force
199-
for (int docId = 0; docId < ctx.reader().maxDoc(); ++docId) {
200-
if (values.advanceExact(docId)) {
201-
final int valueCount = values.docValueCount();
202-
for (int i = 0; i < valueCount; ++i) {
203-
final BytesRef term = values.nextValue();
204-
bucketOrds.add(term);
205-
}
206-
}
207-
}
208-
}
209-
}
210-
211193
// build buckets and store them sorted
212194
final int size = (int) Math.min(bucketOrds.size(), bucketCountThresholds.getShardSize());
213195
long otherDocCount = 0;

0 commit comments

Comments
 (0)