本文整理汇总了Java中org.elasticsearch.search.facet.FacetBuilders类的典型用法代码示例。如果您正苦于以下问题:Java FacetBuilders类的具体用法?Java FacetBuilders怎么用?Java FacetBuilders使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FacetBuilders类属于org.elasticsearch.search.facet包,在下文中一共展示了FacetBuilders类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toFacetBuilders
import org.elasticsearch.search.facet.FacetBuilders; //导入依赖的package包/类
@Override
public List<FacetBuilder> toFacetBuilders(Map<String, Attribute> facetAttributes) {
List<FacetBuilder> facets = new ArrayList<>();
if (facetAttributes == null || facetAttributes.size() == 0)
return facets;
Set<String> keys = facetAttributes.keySet();
for (String key : keys) {
Attribute attribute = facetAttributes.get(key);
String attributeCode = toHashOrOptionFacetAttributeCode(attribute);
if (attributeCode != null) {
facets.add(FacetBuilders.termsFacet(attributeCode).fields(attributeCode));
}
}
return facets;
}
示例2: getContributionsByCandName
import org.elasticsearch.search.facet.FacetBuilders; //导入依赖的package包/类
public void getContributionsByCandName(Client client, String candName, int i)
{
QueryBuilder matchQuery = QueryBuilders.matchQuery("candNm", candName);
FilterBuilder contribRangeFilter = FilterBuilders.rangeFilter("contbReceiptAmt").gte(i);
StatisticalFacetBuilder facet = FacetBuilders.statisticalFacet("stat1").field("contbReceiptAmt");
SearchRequestBuilder request = client.prepareSearch("contributions")
.addSort(SortBuilders.fieldSort("contbReceiptAmt").order(SortOrder.DESC))
.setSearchType(SearchType.QUERY_THEN_FETCH).setQuery(matchQuery).setPostFilter(contribRangeFilter)
.addFacet(facet).setFrom(0).setSize(100)
.addFields("contbrNm", "candNm", "contbrEmployer", "contbReceiptAmt");
System.out.println("SEARCH QUERY: " + request.toString());
SearchResponse response = request.execute().actionGet();
SearchHits searchHits = response.getHits();
SearchHit[] hits = searchHits.getHits();
for (SearchHit hit : hits)
{
Map<String, SearchHitField> fields = hit.getFields();
System.out.println(hit.getId() + ", contbrEmployer=" + fields.get("contbrEmployer").getValue().toString());
}
}
示例3: convertHistogramScriptFacet
import org.elasticsearch.search.facet.FacetBuilders; //导入依赖的package包/类
private static HistogramScriptFacetBuilder convertHistogramScriptFacet(
String label, HistogramFacet facet, String filterJson, FilterBuilder visibilityFilter) {
final HistogramScriptFacetBuilder hsf = FacetBuilders.histogramScriptFacet(label);
hsf.keyScript(facet.getFacetValue().getKeyValueScript().getKeyScript());
hsf.valueScript(facet.getFacetValue().getKeyValueScript().getValueScript());
if (facet.getFacetValue().getKeyValueScript().isSetScriptParams()) {
for (final Map.Entry<String, Object> entry : convertParamsList(
facet.getFacetValue().getKeyValueScript().getScriptParams()).entrySet()) {
hsf.param(entry.getKey(), entry.getValue());
}
}
addFacetFilter(hsf, filterJson, visibilityFilter);
return hsf;
}
示例4: testHistogramFacet
import org.elasticsearch.search.facet.FacetBuilders; //导入依赖的package包/类
@Test
public void testHistogramFacet() {
HistogramFacetBuilder facet =
FacetBuilders.histogramFacet(histogramFacetName).field("speech_number").interval(1);
SearchResponse response =
client.prepareSearch(indexShakeSpeare)
.setQuery(QueryBuilders.termQuery(fieldShakeSpeare, targetText)).addFacet(facet)
.execute().actionGet();
HistogramFacet f = (HistogramFacet) response.getFacets().facetsAsMap().get(histogramFacetName);
// For each entry
for (HistogramFacet.Entry entry : f) {
// Key (X-Axis)
System.out.println(String.format("Key (X-Axis): %d", entry.getKey()));
// Doc count (Y-Axis)
System.out.println(String.format("Doc count (Y-Axis): %d", entry.getCount()));;
}
}
示例5: testFilterFacet
import org.elasticsearch.search.facet.FacetBuilders; //导入依赖的package包/类
@Test
public void testFilterFacet() {
FilterFacetBuilder filterFacet =
FacetBuilders
.filterFacet(filterFacetName, FilterBuilders.termFilter("speaker", "MORTIMER"));
SearchResponse response =
client.prepareSearch(indexShakeSpeare)
.setQuery(QueryBuilders.termQuery(fieldShakeSpeare, targetText)).addFacet(filterFacet)
.execute().actionGet();
FilterFacet f = (FilterFacet) response.getFacets().facetsAsMap().get(filterFacetName);
// Number of docs that matched
System.out.println(String.format("Number of docs that matched: %d", f.getCount()));
}
示例6: ShellScope
import org.elasticsearch.search.facet.FacetBuilders; //导入依赖的package包/类
/**
* Creates a new <code>ShellScope</code> given the actual scope object
* @param scope the actual scope object that depends on the engine in use
*/
ShellScope(Scope scope, ResourceRegistry resourceRegistry) {
this.scope = scope;
this.resourceRegistry = resourceRegistry;
registerJavaClass(Requests.class);
registerJavaClass(SearchSourceBuilder.class);
registerJavaClass(QueryBuilders.class);
registerJavaClass(FilterBuilders.class);
registerJavaClass(SortBuilders.class);
registerJavaClass(FacetBuilders.class);
registerJavaClass(RescoreBuilder.class);
registerJavaClass(SuggestBuilder.class);
registerJavaClass(AliasAction.class);
registerJavaClass(HttpParameters.class);
registerJavaClass(AllocateAllocationCommand.class);
registerJavaClass(CancelAllocationCommand.class);
registerJavaClass(MoveAllocationCommand.class);
registerJavaClass(ShardId.class);
}
示例7: toFacetBuilders
import org.elasticsearch.search.facet.FacetBuilders; //导入依赖的package包/类
@Override
public List<FacetBuilder> toFacetBuilders(Map<String, Attribute> filterAttributes) {
List<FacetBuilder> facets = new ArrayList<>();
if (filterAttributes == null || filterAttributes.size() == 0)
return facets;
Set<String> keys = filterAttributes.keySet();
for (String key : keys) {
Attribute attr = filterAttributes.get(key);
String attrCode = null;
List<FilterIndexField> indexFields = attr.getProductListFilterIndexFields();
if (indexFields != null && indexFields.contains(FilterIndexField.ATT_SLUG)) {
attrCode = toSlugAttributeCode(attr.getCode(), true);
} else if (indexFields != null && indexFields.contains(FilterIndexField.NATIVE)) {
attrCode = attr.getCode();
}
if (attrCode != null) {
FilterType filterType = attr.getProductListFilterType();
if (filterType == FilterType.RANGE) {
facets.add(FacetBuilders.rangeFacet(attrCode).addRange(0, 50).addRange(51, 100).addRange(101, 150)
.addRange(151, 200).addRange(201, 500).addRange(501, 1000).addRange(1001, 1500)
.addRange(1501, 2000).addRange(2001, 5000).addUnboundedTo(5001).field(attrCode));
} else {
facets.add(FacetBuilders.termsFacet(attrCode).fields(attrCode));
}
}
}
return facets;
}
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:35,代码来源:DefaultElasticsearchHelper.java
示例8: getPriceRangeFacet
import org.elasticsearch.search.facet.FacetBuilders; //导入依赖的package包/类
private RangeFacetBuilder getPriceRangeFacet(String facetCode)
{
return FacetBuilders.rangeFacet(facetCode)
.field(SearchDocumentFieldName.PRICE.getFieldName())
.addRange(0, 10)
.addRange(10, 20)
.addRange(20, 100);
}
示例9: convertTermFacet
import org.elasticsearch.search.facet.FacetBuilders; //导入依赖的package包/类
private static TermsFacetBuilder convertTermFacet(
String label, TermsFacet facet, String filterJson, FilterBuilder visibilityFilter) {
final TermsFacetBuilder tf =
FacetBuilders.termsFacet(label).fields(facet.getFields().toArray(new String[facet.getFieldsSize()]));
// Order
if (facet.isSetOrder()) {
tf.order(
org.elasticsearch.search.facet.terms.TermsFacet.ComparatorType.valueOf(
facet.getOrder().toString()));
}
// Exclusions
if (facet.isSetExclude()) {
tf.exclude(facet.getExclude().toArray());
}
// Regex
if (facet.isSetRegex()) {
tf.regex(facet.getRegex());
}
// Size
if (facet.isSetSize()) {
tf.size(facet.getSize());
}
// All terms
if (facet.isSetAllTerms()) {
tf.allTerms(facet.isAllTerms());
}
addFacetFilter(tf, filterJson, visibilityFilter);
return tf;
}
示例10: convertHistogramFacet
import org.elasticsearch.search.facet.FacetBuilders; //导入依赖的package包/类
private static HistogramFacetBuilder convertHistogramFacet(
String label, HistogramFacet facet, String filterJson, FilterBuilder visibilityFilter) {
final HistogramFacetBuilder hf = FacetBuilders.histogramFacet(label).interval(facet.getInterval());
if (facet.getFacetValue().isSet(BaseFacetValue._Fields.FACET_FIELD)) {
hf.field(facet.getFacetValue().getFacetField());
} else {
hf.keyField(facet.getFacetValue().getKeyValueFacet().getKey_field_name()).valueField(
facet.getFacetValue().getKeyValueFacet().getValue_field());
}
addFacetFilter(hf, filterJson, visibilityFilter);
return hf;
}
示例11: convertFilterFacet
import org.elasticsearch.search.facet.FacetBuilders; //导入依赖的package包/类
private static FilterFacetBuilder convertFilterFacet(
String label, FilterFacet facet, String filterJson, FilterBuilder visibilityFilter) {
final FilterFacetBuilder ff = FacetBuilders.filterFacet(label);
ff.filter(FilterBuilders.queryFilter(QueryBuilders.queryString(facet.getLuceneQuery())));
addFacetFilter(ff, filterJson, visibilityFilter);
return ff;
}
示例12: convertStatisticalFacet
import org.elasticsearch.search.facet.FacetBuilders; //导入依赖的package包/类
private static FacetBuilder convertStatisticalFacet(
String label, StatisticalFacet facet, String filterJson, FilterBuilder visibilityFilter) {
if (facet.isSet(StatisticalFacet._Fields.SCRIPT)) {
// Script based
final StatisticalScriptFacetBuilder ssf = FacetBuilders.statisticalScriptFacet(label);
ssf.script(facet.getScript().getScript());
if (facet.getScript().isSetParams()) {
for (final Map.Entry<String, Object> entry : convertParamsList(facet.getScript().getParams())
.entrySet()) {
ssf.param(entry.getKey(), entry.getValue());
}
}
addFacetFilter(ssf, filterJson, visibilityFilter);
return ssf;
} else if (facet.isSet(StatisticalFacet._Fields.FIELDS)) {
// Traditional
final StatisticalFacetBuilder sf = FacetBuilders.statisticalFacet(label);
if (facet.getFields().size() > 1) {
sf.fields(facet.getFields().toArray(new String[facet.getFields().size()]));
} else {
sf.field(facet.getFields().get(0));
}
addFacetFilter(sf, filterJson, visibilityFilter);
return sf;
}
return null;
}
示例13: convertTermsStatsFacet
import org.elasticsearch.search.facet.FacetBuilders; //导入依赖的package包/类
private static TermsStatsFacetBuilder convertTermsStatsFacet(
String label, TermsStatsFacet facet, String filterJson, FilterBuilder visibilityFilter) {
final TermsStatsFacetBuilder tsf = FacetBuilders.termsStatsFacet(label);
// Order
if (facet.isSetOrder()) {
tsf.order(
org.elasticsearch.search.facet.termsstats.TermsStatsFacet.ComparatorType.valueOf(
facet.getOrder().toString()));
}
// Key
if (facet.isSetKeyField()) {
tsf.keyField(facet.getKeyField());
}
// Value/Value Script
if (facet.isSetValueField()) {
if (facet.getValueField().isSet(TermsStatsValue._Fields.VALUE_SCRIPT)) {
tsf.valueScript(facet.getValueField().getValueScript().getScript());
} else {
tsf.valueField(facet.getValueField().getValueField());
}
}
// Size
if (facet.isSetSize()) {
tsf.size(facet.getSize());
}
// All terms
if (facet.isSetAllTerms() && facet.isAllTerms()) {
tsf.allTerms();
}
addFacetFilter(tsf, filterJson, visibilityFilter);
return tsf;
}
示例14: testFacets
import org.elasticsearch.search.facet.FacetBuilders; //导入依赖的package包/类
@Test
public void testFacets() {
// obtain all line contains "henry"
SearchResponse response =
client.prepareSearch(indexShakeSpeare)
.setQuery(QueryBuilders.termQuery(fieldShakeSpeare, targetText))
.addFacet(FacetBuilders.termsFacet(facetName).field("speaker").size(20)).execute()
.actionGet();
// read response
TermsFacet f = (TermsFacet) response.getFacets().facetsAsMap().get(facetName);
// Total terms doc count
System.out.println(String.format("Total terms doc count: %d", f.getTotalCount()));
// Not shown terms doc count
System.out.println(String.format("Not shown terms doc count: %d", f.getOtherCount()));
// Without term doc count
System.out.println(String.format("Without term doc count: %d", f.getMissingCount()));
// For each entry
for (TermsFacet.Entry entry : f) {
System.out.println(String.format("Term: %s", entry.getTerm()));
System.out.println(String.format("Doc count: %d", entry.getCount()));
}
}
示例15: testQueryFacet
import org.elasticsearch.search.facet.FacetBuilders; //导入依赖的package包/类
@Test
public void testQueryFacet() {
MatchQueryBuilder matchQuery = QueryBuilders.matchQuery(fieldShakeSpeare, "havoc");
QueryFacetBuilder queryFacet = FacetBuilders.queryFacet(queryFacetName, matchQuery);
// no need to add query since facet itself is a query
SearchResponse response =
client.prepareSearch(indexShakeSpeare).addFacet(queryFacet).execute().actionGet();
QueryFacet f = (QueryFacet) response.getFacets().facetsAsMap().get(queryFacetName);
// Number of docs that matched
System.out.println(String.format("Number of docs that matched: %d", f.getCount()));
}