added annotation for multfield
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
package org.springframework.data.elasticsearch;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldIndex.analyzed;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldIndex.not_analyzed;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.Integer;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.String;
|
||||
|
||||
/**
|
||||
* Simple type to test facets
|
||||
*/
|
||||
@@ -18,10 +22,16 @@ public class Article {
|
||||
|
||||
private String title;
|
||||
|
||||
@Field(type = "string", facetable = true)
|
||||
@MultiField(
|
||||
mainField = @Field(type = String, index = analyzed),
|
||||
otherFields = {
|
||||
@NestedField(dotSuffix = "untouched", type = String, store = true, index = not_analyzed),
|
||||
@NestedField(dotSuffix = "sort", type = String, store = true, indexAnalyzer = "keyword")
|
||||
}
|
||||
)
|
||||
private List<String> authors = new ArrayList<String>();
|
||||
|
||||
@Field(type = "integer", facetable = true)
|
||||
@Field(type = Integer, store = true)
|
||||
private List<Integer> publishedYears = new ArrayList<Integer>();
|
||||
|
||||
public Article() {
|
||||
|
||||
@@ -18,6 +18,11 @@ package org.springframework.data.elasticsearch;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldIndex;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldIndex.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
@@ -26,40 +31,41 @@ import org.springframework.data.elasticsearch.annotations.Field;
|
||||
@Document(indexName = "test-mapping", type = "mapping", indexStoreType = "memory", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SampleMappingEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@Field(type = "string", index = "not_analyzed", store = true, searchAnalyzer = "standard", indexAnalyzer = "standard")
|
||||
private String message;
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private NestedEntity nested;
|
||||
@Field(type = String, index = not_analyzed, store = true, searchAnalyzer = "standard", indexAnalyzer = "standard")
|
||||
private String message;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
private NestedEntity nested;
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
static class NestedEntity {
|
||||
@Field(type = "string")
|
||||
private String someField;
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getSomeField() {
|
||||
return someField;
|
||||
}
|
||||
static class NestedEntity {
|
||||
@Field(type = String)
|
||||
private String someField;
|
||||
|
||||
public void setSomeField(String someField) {
|
||||
this.someField = someField;
|
||||
}
|
||||
}
|
||||
public String getSomeField() {
|
||||
return someField;
|
||||
}
|
||||
|
||||
public void setSomeField(String someField) {
|
||||
this.someField = someField;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class ElasticsearchTemplateFacetTests {
|
||||
|
||||
// given
|
||||
String facetName = "fauthors";
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withFacet(new TermFacetRequestBuilder(facetName).withStringFields("authors").build()).build();
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withFacet(new TermFacetRequestBuilder(facetName).withFields("authors.untouched").build()).build();
|
||||
// when
|
||||
FacetedPage<Article> result = elasticsearchTemplate.queryForPage(searchQuery, Article.class);
|
||||
// then
|
||||
@@ -109,8 +109,8 @@ public class ElasticsearchTemplateFacetTests {
|
||||
// given
|
||||
String facetName = "fauthors";
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||
.withFilter(FilterBuilders.notFilter(FilterBuilders.termFilter("title","four")))
|
||||
.withFacet(new TermFacetRequestBuilder(facetName).applyQueryFilter().withStringFields("authors").build()).build();
|
||||
.withFilter(FilterBuilders.notFilter(FilterBuilders.termFilter("title", "four")))
|
||||
.withFacet(new TermFacetRequestBuilder(facetName).applyQueryFilter().withFields("authors.untouched").build()).build();
|
||||
// when
|
||||
FacetedPage<Article> result = elasticsearchTemplate.queryForPage(searchQuery, Article.class);
|
||||
// then
|
||||
@@ -136,7 +136,7 @@ public class ElasticsearchTemplateFacetTests {
|
||||
// given
|
||||
String facetName = "fauthors";
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||
.withFacet(new TermFacetRequestBuilder(facetName).withStringFields("authors").ascTerm().build()).build();
|
||||
.withFacet(new TermFacetRequestBuilder(facetName).withFields("authors.untouched").ascTerm().build()).build();
|
||||
// when
|
||||
FacetedPage<Article> result = elasticsearchTemplate.queryForPage(searchQuery, Article.class);
|
||||
// then
|
||||
@@ -167,7 +167,7 @@ public class ElasticsearchTemplateFacetTests {
|
||||
// given
|
||||
String facetName = "fauthors";
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||
.withFacet(new TermFacetRequestBuilder(facetName).withStringFields("authors").ascCount().build()).build();
|
||||
.withFacet(new TermFacetRequestBuilder(facetName).withFields("authors.untouched").ascCount().build()).build();
|
||||
// when
|
||||
FacetedPage<Article> result = elasticsearchTemplate.queryForPage(searchQuery, Article.class);
|
||||
// then
|
||||
@@ -197,7 +197,7 @@ public class ElasticsearchTemplateFacetTests {
|
||||
// given
|
||||
String facetName = "fyears";
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||
.withFacet(new TermFacetRequestBuilder(facetName).withNumberFields("publishedYears").descCount().build()).build();
|
||||
.withFacet(new TermFacetRequestBuilder(facetName).withFields("publishedYears").descCount().build()).build();
|
||||
// when
|
||||
FacetedPage<Article> result = elasticsearchTemplate.queryForPage(searchQuery, Article.class);
|
||||
// then
|
||||
@@ -227,7 +227,7 @@ public class ElasticsearchTemplateFacetTests {
|
||||
// given
|
||||
String facetName = "fyears";
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||
.withFacet(new TermFacetRequestBuilder(facetName).withNumberFields("publishedYears").withStringFields("authors").ascTerm().build()).build();
|
||||
.withFacet(new TermFacetRequestBuilder(facetName).withFields("publishedYears", "authors.untouched").ascTerm().build()).build();
|
||||
// when
|
||||
FacetedPage<Article> result = elasticsearchTemplate.queryForPage(searchQuery, Article.class);
|
||||
// then
|
||||
@@ -274,8 +274,8 @@ public class ElasticsearchTemplateFacetTests {
|
||||
String numberFacetName = "fAuthors";
|
||||
String stringFacetName = "fyears";
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||
.withFacet(new TermFacetRequestBuilder(numberFacetName).withNumberFields("publishedYears").ascTerm().build())
|
||||
.withFacet(new TermFacetRequestBuilder(stringFacetName).withStringFields("authors").ascTerm().build())
|
||||
.withFacet(new TermFacetRequestBuilder(numberFacetName).withFields("publishedYears").ascTerm().build())
|
||||
.withFacet(new TermFacetRequestBuilder(stringFacetName).withFields("authors.untouched").ascTerm().build())
|
||||
.build();
|
||||
// when
|
||||
FacetedPage<Article> result = elasticsearchTemplate.queryForPage(searchQuery, Article.class);
|
||||
|
||||
Reference in New Issue
Block a user