Skip to content

Commit 118c3bb

Browse files
committed
some new features for the term lists
1 parent c3c77f6 commit 118c3bb

File tree

11 files changed

+251
-85
lines changed

11 files changed

+251
-85
lines changed

README.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
# Elasticsearch Index Termlist Plugin
22

3-
This plugin extends Elasticsearch with a term list capability, not only revealing all occuring terms but
4-
also stating each terms frequency. Term lists can be generated from indexes, or even of all of the
5-
indexes in the cluster.
3+
This plugin extends Elasticsearch with a term list capability. It presents a list of terms in a field of an index
4+
and can also list each terms frequency. Term lists can be generated from one index or even of all of the
5+
indexes.
66

77
## Versions
88

99
| Elasticsearch | Plugin | Release date |
1010
| -------------- | ------------ | ------------ |
11+
| 1.3.2 | 1.3.0.0 | Aug 21, 2014 |
1112
| 1.2.1 | 1.2.1.0 | Jul 3, 2014 |
1213

1314
## Installation
1415

15-
./bin/plugin -install index-termlist -url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-index-termlist/1.2.1.0/elasticsearch-index-termlist-1.2.1.0-plugin.zip
16+
./bin/plugin -install index-termlist -url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-index-termlist/1.3.0.0/elasticsearch-index-termlist-1.3.0.0-plugin.zip
1617

1718
Do not forget to restart the node after installing.
1819

1920
## Checksum
2021

2122
| File | SHA1 |
2223
| ------------------------------------------------- | -----------------------------------------|
24+
| elasticsearch-index-termlist-1.3.0.0-plugin.zip | 07ea40e85584c9887337c14ec5cca098a31089b5 |
2325
| elasticsearch-index-termlist-1.2.1.0-plugin.zip | c51a8d626b32a4a6cd2ac4335b5578f0e5cccaa6 |
2426

2527
## Project docs
2628

27-
The Maven project site is available at [Github](http://jprante.github.io/elasticsearch-index-termlis)
29+
The Maven project site is available at [Github](http://jprante.github.io/elasticsearch-index-termlist)
2830

2931
## Issues
3032

31-
All feedback is welcome! If you find issues, please post them at [Github](https://github.com/jprante/elasticsearch-index-termlis/issues)
33+
All feedback is welcome! If you find issues, please post them at [Github](https://github.com/jprante/elasticsearch-index-termlist/issues)
3234

3335
# Introduction
3436

@@ -48,34 +50,42 @@ like `_uid`, `_all`, or `_type` are always skipped.
4850

4951
# Example
5052

51-
Consider the following example index::
53+
Consider the following example index
5254

55+
curl -XDELETE 'http://localhost:9200/test/'
5356
curl -XPUT 'http://localhost:9200/test/'
5457
curl -XPUT 'http://localhost:9200/test/test/1' -d '{ "test": "Hello World" }'
5558
curl -XPUT 'http://localhost:9200/test/test/2' -d '{ "test": "Hello Jörg Prante" }'
5659
curl -XPUT 'http://localhost:9200/test/test/3' -d '{ "message": "elastic search" }'
5760

58-
Get term list of index ``test``::
61+
Get term list of index ``test``
5962

6063
curl -XGET 'http://localhost:9200/test/_termlist'
61-
{"_shards":{"total":5,"successful":5,"failed":0},"terms":[{"name":"search"},{"name":"prante"},{"name":"hello"},{"name":"elastic"},{"name":"world"},{"name":"jörg"}]}
64+
{"_shards":{"total":5,"successful":5,"failed":0},"total":6,"terms":[{"name":"search"},{"name":"prante"},{"name":"hello"},{"name":"world"},{"name":"jörg"},{"name":"elastic"}]}
6265

63-
Get term list of index `test` of field `message`::
66+
Get term list of index `test` of field `message`
6467

6568
curl -XGET 'http://localhost:9200/test/_termlist?field=message'
66-
{"_shards":{"total":5,"successful":5,"failed":0},"terms":[{"name":"elastic"},{"name":"search"}]}
69+
{"_shards":{"total":5,"successful":5,"failed":0},"total":2,"terms":[{"name":"elastic"},{"name":"search"}]}
6770

68-
Get term list of index `test` with total frequencies::
71+
Get term list of index `test` with total frequencies
6972

7073
curl -XGET 'http://localhost:9200/test/_termlist?totalfreqs'
71-
{"_shards":{"total":5,"successful":5,"failed":0},"terms":[{"name":"hello","totalfreq":2},{"name":"world","totalfreq":1},{"name":"search","totalfreq":1},{"name":"prante","totalfreq":1},{"name":"jörg","totalfreq":1},{"name":"elastic","totalfreq":1}]}
74+
{"_shards":{"total":5,"successful":5,"failed":0},"total":6,"terms":[{"name":"search","totalfreq":1},{"name":"prante","totalfreq":1},{"name":"hello","totalfreq":2},{"name":"world","totalfreq":1},{"name":"jörg","totalfreq":1},{"name":"elastic","totalfreq":1}]}
7275

73-
74-
Get term list of index `test` with total frequencies but only the first three terms of the list::
76+
Get term list of index `test` with total frequencies but only the first three terms of the list
7577

7678
curl -XGET 'http://localhost:9200/test/_termlist?totalfreqs&size=3'
77-
{"_shards":{"total":5,"successful":5,"failed":0},"terms":[{"name":"hello","totalfreq":2},{"name":"world","totalfreq":1},{"name":"search","totalfreq":1}]}
79+
{"_shards":{"total":5,"successful":5,"failed":0},"total":6,"terms":[{"name":"prante","totalfreq":1},{"name":"hello","totalfreq":2},{"name":"world","totalfreq":1}]}
80+
81+
Get term list of terms starting with `hello` in index `test` field `test`, with total frequencies. This can be useful to estimate hits.
82+
83+
curl -XGET 'http://localhost:9200/test/_termlist?field=test&term=hello&totalfreqs'
84+
{"_shards":{"total":5,"successful":5,"failed":0},"total":1,"terms":[{"name":"hello","totalfreq":2}]}
85+
86+
A complete sorted list of terms in your index beginning with `a`, pageable, complete with frequencies
7887

88+
curl -XGET 'http://localhost:9200/books/_termlist?term=a&totalfreqs&sortbyterms&pretty&from=0&size=100'
7989

8090
# Caution
8191

pom.xml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.xbib.elasticsearch.plugin</groupId>
88
<artifactId>elasticsearch-index-termlist</artifactId>
9-
<version>1.2.1.0</version>
9+
<version>1.3.0.0</version>
1010

1111
<packaging>jar</packaging>
1212

@@ -45,24 +45,11 @@
4545
</repository>
4646
</distributionManagement>
4747

48-
<repositories>
49-
<repository>
50-
<id>xbib</id>
51-
<url>http://xbib.org/repository</url>
52-
<releases>
53-
<enabled>true</enabled>
54-
</releases>
55-
<snapshots>
56-
<enabled>true</enabled>
57-
</snapshots>
58-
</repository>
59-
</repositories>
60-
6148
<properties>
6249
<github.global.server>github</github.global.server>
6350
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6451
<java.compile.version>1.7</java.compile.version>
65-
<elasticsearch.version>1.2.1</elasticsearch.version>
52+
<elasticsearch.version>1.3.2</elasticsearch.version>
6653
</properties>
6754

6855
<dependencies>

src/main/java/org/xbib/elasticsearch/action/termlist/ShardTermlistRequest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class ShardTermlistRequest extends BroadcastShardOperationRequest {
1010

1111
private String field;
1212

13+
private String term;
14+
15+
private Integer from;
16+
1317
private Integer size;
1418

1519
private boolean withDocFreq;
@@ -22,6 +26,8 @@ class ShardTermlistRequest extends BroadcastShardOperationRequest {
2226
public ShardTermlistRequest(String index, int shardId, TermlistRequest request) {
2327
super(index, shardId, request);
2428
this.field = request.getField();
29+
this.term = request.getTerm();
30+
this.from = request.getFrom();
2531
this.size = request.getSize();
2632
this.withDocFreq = request.getWithDocFreq();
2733
this.withTotalFreq = request.getWithTotalFreq();
@@ -35,6 +41,22 @@ public String getField() {
3541
return field;
3642
}
3743

44+
public void setTerm(String term) {
45+
this.term = term;
46+
}
47+
48+
public String getTerm() {
49+
return term;
50+
}
51+
52+
public void setFrom(Integer from) {
53+
this.from = from;
54+
}
55+
56+
public Integer getFrom() {
57+
return from;
58+
}
59+
3860
public void setSize(Integer size) {
3961
this.size = size;
4062
}
@@ -63,6 +85,9 @@ public boolean getWithTotalFreq() {
6385
public void readFrom(StreamInput in) throws IOException {
6486
super.readFrom(in);
6587
field = in.readString();
88+
term = in.readString();
89+
from = in.readInt();
90+
size = in.readInt();
6691
withDocFreq = in.readBoolean();
6792
withTotalFreq = in.readBoolean();
6893
}
@@ -71,6 +96,9 @@ public void readFrom(StreamInput in) throws IOException {
7196
public void writeTo(StreamOutput out) throws IOException {
7297
super.writeTo(out);
7398
out.writeString(field);
99+
out.writeString(term);
100+
out.writeInt(from);
101+
out.writeInt(size);
74102
out.writeBoolean(withDocFreq);
75103
out.writeBoolean(withTotalFreq);
76104
}

src/main/java/org/xbib/elasticsearch/action/termlist/TermInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
public class TermInfo implements Streamable {
1010

11-
Integer docFreq;
11+
private Integer docFreq;
1212

13-
Long totalFreq;
13+
private Long totalFreq;
1414

1515
public TermInfo docfreq(int docFreq) {
1616
this.docFreq = docFreq;

src/main/java/org/xbib/elasticsearch/action/termlist/TermlistAction.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package org.xbib.elasticsearch.action.termlist;
22

3-
import org.elasticsearch.action.Action;
3+
import org.elasticsearch.action.ClientAction;
44
import org.elasticsearch.client.Client;
5-
import org.elasticsearch.client.internal.InternalGenericClient;
65

7-
public class TermlistAction extends Action<TermlistRequest, TermlistResponse, TermlistRequestBuilder> {
6+
public class TermlistAction extends ClientAction<TermlistRequest, TermlistResponse, TermlistRequestBuilder> {
87

98
public static final TermlistAction INSTANCE = new TermlistAction();
109

@@ -21,6 +20,6 @@ public TermlistResponse newResponse() {
2120

2221
@Override
2322
public TermlistRequestBuilder newRequestBuilder(Client client) {
24-
return new TermlistRequestBuilder((InternalGenericClient) client);
23+
return new TermlistRequestBuilder(client);
2524
}
2625
}

src/main/java/org/xbib/elasticsearch/action/termlist/TermlistRequest.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,22 @@ public class TermlistRequest extends BroadcastOperationRequest<TermlistRequest>
1010

1111
private String field;
1212

13+
private String term;
14+
15+
private Integer from;
16+
1317
private Integer size;
1418

1519
private boolean withDocFreq;
1620

1721
private boolean withTotalFreq;
1822

23+
private boolean sortByTerm;
24+
25+
private boolean sortByDocFreq;
26+
27+
private boolean sortByTotalFreq;
28+
1929
TermlistRequest() {
2030
}
2131

@@ -31,6 +41,22 @@ public String getField() {
3141
return field;
3242
}
3343

44+
public void setTerm(String term) {
45+
this.term = term;
46+
}
47+
48+
public String getTerm() {
49+
return term;
50+
}
51+
52+
public void setFrom(Integer from) {
53+
this.from = from;
54+
}
55+
56+
public Integer getFrom() {
57+
return from;
58+
}
59+
3460
public void setSize(Integer size) {
3561
this.size = size;
3662
}
@@ -55,15 +81,54 @@ public boolean getWithTotalFreq() {
5581
return withTotalFreq;
5682
}
5783

84+
public void sortByTerm(boolean sortByTerm) {
85+
this.sortByTerm = sortByTerm;
86+
}
87+
88+
public boolean sortByTerm() {
89+
return sortByTerm;
90+
}
91+
92+
public void sortByDocFreq(boolean sortByDocFreq) {
93+
this.sortByDocFreq = sortByDocFreq;
94+
}
95+
96+
public boolean sortByDocFreq() {
97+
return sortByDocFreq;
98+
}
99+
100+
public void sortByTotalFreq(boolean sortByTotalFreq) {
101+
this.sortByTotalFreq = sortByTotalFreq;
102+
}
103+
104+
public boolean sortByTotalFreq() {
105+
return sortByTotalFreq;
106+
}
107+
58108
@Override
59109
public void readFrom(StreamInput in) throws IOException {
60110
super.readFrom(in);
61111
field = in.readString();
112+
term = in.readString();
113+
from = in.readInt();
114+
size = in.readInt();
115+
withDocFreq = in.readBoolean();
116+
withTotalFreq = in.readBoolean();
117+
sortByDocFreq = in.readBoolean();
118+
sortByTotalFreq = in.readBoolean();
119+
62120
}
63121

64122
@Override
65123
public void writeTo(StreamOutput out) throws IOException {
66124
super.writeTo(out);
67125
out.writeString(field);
126+
out.writeString(term);
127+
out.writeInt(from);
128+
out.writeInt(size);
129+
out.writeBoolean(withDocFreq);
130+
out.writeBoolean(withTotalFreq);
131+
out.writeBoolean(sortByDocFreq);
132+
out.writeBoolean(sortByTotalFreq);
68133
}
69134
}

src/main/java/org/xbib/elasticsearch/action/termlist/TermlistRequestBuilder.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,36 @@
33
import org.elasticsearch.action.ActionListener;
44
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder;
55
import org.elasticsearch.client.Client;
6-
import org.elasticsearch.client.internal.InternalGenericClient;
76

87
/**
98
* A request to get termlists of one or more indices.
109
*/
11-
public class TermlistRequestBuilder extends BroadcastOperationRequestBuilder<TermlistRequest, TermlistResponse, TermlistRequestBuilder> {
10+
public class TermlistRequestBuilder extends BroadcastOperationRequestBuilder<TermlistRequest, TermlistResponse, TermlistRequestBuilder, Client> {
1211

13-
public TermlistRequestBuilder(InternalGenericClient client) {
12+
public TermlistRequestBuilder(Client client) {
1413
super(client, new TermlistRequest());
1514
}
1615

16+
public TermlistRequestBuilder setField(String field) {
17+
request.setField(field);
18+
return this;
19+
}
20+
21+
public TermlistRequestBuilder setTerm(String term) {
22+
request.setTerm(term);
23+
return this;
24+
}
25+
26+
public TermlistRequestBuilder setFrom(Integer from) {
27+
request.setFrom(from);
28+
return this;
29+
}
30+
31+
public TermlistRequestBuilder setSize(Integer size) {
32+
request.setSize(size);
33+
return this;
34+
}
35+
1736
public TermlistRequestBuilder withDocFreq() {
1837
request.setWithDocFreq(true);
1938
return this;
@@ -24,8 +43,19 @@ public TermlistRequestBuilder withTotalFreq() {
2443
return this;
2544
}
2645

46+
public TermlistRequestBuilder sortByDocFreq(boolean sortByDocFreq) {
47+
request.sortByDocFreq(sortByDocFreq);
48+
return this;
49+
}
50+
51+
public TermlistRequestBuilder sortByTotalFreq(boolean sortByTotalFreq) {
52+
request.sortByTotalFreq(sortByTotalFreq);
53+
return this;
54+
}
55+
56+
2757
@Override
2858
protected void doExecute(ActionListener<TermlistResponse> listener) {
29-
((Client) client).execute(TermlistAction.INSTANCE, request, listener);
59+
client.execute(TermlistAction.INSTANCE, request, listener);
3060
}
3161
}

0 commit comments

Comments
 (0)