当前位置: 首页>>代码示例>>Java>>正文


Java QueryBuilders.termQuery方法代码示例

本文整理汇总了Java中org.elasticsearch.index.query.QueryBuilders.termQuery方法的典型用法代码示例。如果您正苦于以下问题:Java QueryBuilders.termQuery方法的具体用法?Java QueryBuilders.termQuery怎么用?Java QueryBuilders.termQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.index.query.QueryBuilders的用法示例。


在下文中一共展示了QueryBuilders.termQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
/**
 * Here to establish QueryBuilder patterns
 */
void test() {
	SearchSourceBuilder b;
	BoolQueryBuilder qb = QueryBuilders.boolQuery();
	QueryBuilder qbmm = QueryBuilders.multiMatchQuery("name", "fieldNames");
	QueryBuilder qbm = QueryBuilders.matchQuery("name", "text");
	QueryBuilder qbmp = QueryBuilders.matchPhraseQuery("name", "text");
	QueryBuilder qb1 = QueryBuilders.termQuery(ITQCoreOntology.TUPLE_SUBJECT_PROPERTY, "");
	QueryBuilder qb2 = QueryBuilders.termQuery(ITQCoreOntology.TUPLE_OBJECT_PROPERTY, "");
	QueryBuilder qb3 = QueryBuilders.termQuery(ITQCoreOntology.INSTANCE_OF_PROPERTY_TYPE, "");
	qb.must(qb3);
	qb.should(qb1);
	qb.should(qb2);
	QueryBuilder partial = QueryBuilders.regexpQuery("name", "regexp");
	QueryBuilder wildcard = QueryBuilders.wildcardQuery("name", "query");
}
 
开发者ID:topicquests,项目名称:backside-servlet-ks,代码行数:19,代码来源:ElasticQueryDSL.java

示例2: listTopicsByURL

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
@Override
public IResult listTopicsByURL(String url, ITicket credentials) {
	QueryBuilder qb1 = QueryBuilders.termQuery(ITQCoreOntology.RESOURCE_URL_PROPERTY, url);
	IResult result = topicMap.runQuery(qb1.toString(), 0, -1, credentials);
	environment.logDebug("TopicMapModel.listTopicsByURL+ "+result.getErrorString()+" | "+result.getResultObject());
	//TopicMapModel.getTopicByURL+  | [[email protected], [email protected]]
	List<Object> lx = (List<Object>)result.getResultObject();
	if (lx != null) {
		if (lx.size() > 0) {
			try {
				ISubjectProxy n = (SubjectProxy)(lx.get(0));
				result.setResultObject(n);
			} catch (Exception ex) {
				environment.logError(ex.getMessage(), ex);
				result.addErrorString(ex.getMessage());
				result.setResultObject(null);
			}
		} else
			result.setResultObject(null);
	}
	System.out.println("LISTTOPICSBYURL+ "+result.getErrorString()+" | "+result.getResultObject());
	return result;
}
 
开发者ID:topicquests,项目名称:backside-servlet-ks,代码行数:24,代码来源:TopicMapModel.java

示例3: deleteExtendedDataForElement

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
private void deleteExtendedDataForElement(Element element) {
    try {
        QueryBuilder filter = QueryBuilders.termQuery(EXTENDED_DATA_ELEMENT_ID_FIELD_NAME, element.getId());

        SearchRequestBuilder s = getClient().prepareSearch(getIndicesToQuery())
                .setTypes(ELEMENT_TYPE)
                .setQuery(QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).filter(filter))
                .storedFields(
                        EXTENDED_DATA_ELEMENT_ID_FIELD_NAME,
                        EXTENDED_DATA_TABLE_NAME_FIELD_NAME,
                        EXTENDED_DATA_TABLE_ROW_ID_FIELD_NAME
                );
        for (SearchHit hit : s.execute().get().getHits()) {
            if (MUTATION_LOGGER.isTraceEnabled()) {
                LOGGER.trace("deleting extended data document %s", hit.getId());
            }
            getClient().prepareDelete(hit.getIndex(), ELEMENT_TYPE, hit.getId()).execute().actionGet();
        }
    } catch (Exception ex) {
        throw new MemgraphException("Could not delete extended data for element: " + element.getId());
    }
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:23,代码来源:Elasticsearch5SearchIndex.java

示例4: testEmpty

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
public void testEmpty() throws Exception {
    Directory directory = newDirectory();
    RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
    indexWriter.close();
    IndexReader indexReader = DirectoryReader.open(directory);
    IndexSearcher indexSearcher = newSearcher(indexReader, true, true);
    int numFilters = randomIntBetween(1, 10);
    QueryBuilder[] filters = new QueryBuilder[numFilters];
    for (int i = 0; i < filters.length; i++) {
        filters[i] = QueryBuilders.termQuery("field", randomAsciiOfLength(5));
    }
    FiltersAggregationBuilder builder = new FiltersAggregationBuilder("test", filters);
    builder.otherBucketKey("other");
    InternalFilters response = search(indexSearcher, new MatchAllDocsQuery(), builder, fieldType);
    assertEquals(response.getBuckets().size(), numFilters);
    for (InternalFilters.InternalBucket filter : response.getBuckets()) {
        assertEquals(filter.getDocCount(), 0);
    }
    indexReader.close();
    directory.close();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:FiltersAggregatorTests.java

示例5: testSerialize

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
public void testSerialize() throws IOException {
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest("indices");
        validateQueryRequest.query(QueryBuilders.termQuery("field", "value"));
        validateQueryRequest.rewrite(true);
        validateQueryRequest.explain(false);
        validateQueryRequest.types("type1", "type2");
        ShardValidateQueryRequest request = new ShardValidateQueryRequest(new ShardId("index", "foobar", 1),
            new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] {"alias0", "alias1"}), validateQueryRequest);
        request.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
            ShardValidateQueryRequest readRequest = new ShardValidateQueryRequest();
            readRequest.readFrom(in);
            assertEquals(request.filteringAliases(), readRequest.filteringAliases());
            assertArrayEquals(request.types(), readRequest.types());
            assertEquals(request.explain(), readRequest.explain());
            assertEquals(request.query(), readRequest.query());
            assertEquals(request.rewrite(), readRequest.rewrite());
            assertEquals(request.shardId(), readRequest.shardId());
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:ShardValidateQueryRequestTests.java

示例6: countReplies

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
@Override
public long countReplies(String id) {

    // Prepare count request
    SearchRequestBuilder searchRequest = client
            .prepareSearch(getIndex())
            .setTypes(getType())
            .setFetchSource(false)
            .setSearchType(SearchType.QUERY_AND_FETCH)
            .setSize(0);

    // Query = filter on reference
    TermQueryBuilder query = QueryBuilders.termQuery(RecordComment.PROPERTY_REPLY_TO_JSON, id);
    searchRequest.setQuery(query);

    // Execute query
    try {
        SearchResponse response = searchRequest.execute().actionGet();
        return response.getHits().getTotalHits();
    }
    catch(SearchPhaseExecutionException e) {
        // Failed or no item on index
        logger.error(String.format("Error while counting comment replies: %s", e.getMessage()), e);
    }
    return 1;
}
 
开发者ID:duniter-gchange,项目名称:gchange-pod,代码行数:27,代码来源:AbstractCommentDaoImpl.java

示例7: getBookmarkByURL

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
@Override
public IResult getBookmarkByURL(String url, ITicket credentials) {
	QueryBuilder t1 = QueryBuilders.termQuery(ITQCoreOntology.RESOURCE_URL_PROPERTY, url);
	QueryBuilder t2 = QueryBuilders.termQuery(ITQCoreOntology.INSTANCE_OF_PROPERTY_TYPE, INodeTypes.BOOKMARK_TYPE);
	final BoolQueryBuilder query = new BoolQueryBuilder();
	query.must(t1);
	query.must(t2);
	IResult result = topicMap.runQuery(query.toString(), 0, -1, credentials);
	environment.logDebug("TopicMapModel.getBookmarkByURL+ "+result.getErrorString()+" | "+result.getResultObject());
	//TopicMapModel.getTopicByURL+  | [[email protected], [email protected]]
	List<Object> lx = (List<Object>)result.getResultObject();
	if (lx != null) {
		if (lx.size() > 0) {
			try {
				ISubjectProxy n = (SubjectProxy)(lx.get(0));
				result.setResultObject(n);
			} catch (Exception ex) {
				environment.logError(ex.getMessage(), ex);
				result.addErrorString(ex.getMessage());
				result.setResultObject(null);
			}
		} else
			result.setResultObject(null);
	}
	System.out.println("GETBOOKMARKBYURL+ "+result.getErrorString()+" | "+result.getResultObject());
	return result;
}
 
开发者ID:topicquests,项目名称:backside-servlet-ks,代码行数:28,代码来源:TopicMapModel.java

示例8: getDirectionInEdgeFilter

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
private QueryBuilder getDirectionInEdgeFilter() {
    QueryBuilder outVertexIdFilter = QueryBuilders.termQuery(Elasticsearch5SearchIndex.IN_VERTEX_ID_FIELD_NAME, sourceVertex.getId());
    if (otherVertexId != null) {
        QueryBuilder inVertexIdFilter = QueryBuilders.termQuery(Elasticsearch5SearchIndex.OUT_VERTEX_ID_FIELD_NAME, otherVertexId);
        return QueryBuilders.boolQuery()
                .must(outVertexIdFilter)
                .must(inVertexIdFilter);
    }
    return outVertexIdFilter;
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:11,代码来源:ElasticsearchSearchVertexQuery.java

示例9: getDirectionOutEdgeFilter

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
private QueryBuilder getDirectionOutEdgeFilter() {
    QueryBuilder outVertexIdFilter = QueryBuilders.termQuery(Elasticsearch5SearchIndex.OUT_VERTEX_ID_FIELD_NAME, sourceVertex.getId());
    if (otherVertexId != null) {
        QueryBuilder inVertexIdFilter = QueryBuilders.termQuery(Elasticsearch5SearchIndex.IN_VERTEX_ID_FIELD_NAME, otherVertexId);
        return QueryBuilders.boolQuery()
                .must(outVertexIdFilter)
                .must(inVertexIdFilter);
    }
    return outVertexIdFilter;
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:11,代码来源:ElasticsearchSearchVertexQuery.java

示例10: downloadProducts

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
/**
 * Download product from given category.
 *
 * @param request               which contains query category
 * @param productPublishSubject the subject which downloaded product should publish to
 */
public void downloadProducts(DownloadProductsRequest request, PublishSubject<Product> productPublishSubject) {

  QueryBuilder queryBuilder = QueryBuilders.termQuery("category", request.getCategory());
  SearchResponse scrollResponse =
      esClient
          .prepareSearch(INDEX)
          .setScroll(DEFAULT_SCROLL_TIME_VALUE)
          .setTypes(TYPE)
          .setQuery(queryBuilder)
          .setSize(SCROLL_SIZE)
          .get();
  do {
    scrollResponse.getHits().forEach(hit -> {
      try {
        Product.Builder builder = Product.newBuilder();
        jsonParser.merge(hit.sourceAsString(), builder);
        productPublishSubject.onNext(builder.build());
      } catch (IOException ioe) {
        // Don't fail the whole stream
        log.error("Unable to read product record", ioe);
        productPublishSubject.onError(ioe);
        throw new IllegalStateException(ioe);
      }
    });
    // Fetch next batch of cite group records
    scrollResponse =
        esClient
            .prepareSearchScroll(scrollResponse.getScrollId())
            .setScroll(DEFAULT_SCROLL_TIME_VALUE)
            .execute()
            .actionGet();
  } while (scrollResponse.getHits().getHits().length != 0);

  productPublishSubject.onComplete();
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:42,代码来源:ProductDao.java

示例11: testSerialize50Request

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
public void testSerialize50Request() throws IOException {
    ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest("indices");
    validateQueryRequest.query(QueryBuilders.termQuery("field", "value"));
    validateQueryRequest.rewrite(true);
    validateQueryRequest.explain(false);
    validateQueryRequest.types("type1", "type2");
    ShardValidateQueryRequest request = new ShardValidateQueryRequest(new ShardId("index", "foobar", 1),
        new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] {"alias0", "alias1"}), validateQueryRequest);
    BytesArray requestBytes = new BytesArray(Base64.getDecoder()
        // this is a base64 encoded request generated with the same input
        .decode("AAVpbmRleAZmb29iYXIBAQdpbmRpY2VzBAR0ZXJtP4AAAAAFZmllbGQVBXZhbHVlAgV0eXBlMQV0eXBlMgIGYWxpYXMwBmFsaWFzMQABAA"));
    try (StreamInput in = new NamedWriteableAwareStreamInput(requestBytes.streamInput(), namedWriteableRegistry)) {
        in.setVersion(Version.V_5_0_0);
        ShardValidateQueryRequest readRequest = new ShardValidateQueryRequest();
        readRequest.readFrom(in);
        assertEquals(0, in.available());
        assertArrayEquals(request.filteringAliases().getAliases(), readRequest.filteringAliases().getAliases());
        expectThrows(IllegalStateException.class, () -> readRequest.filteringAliases().getQueryBuilder());
        assertArrayEquals(request.types(), readRequest.types());
        assertEquals(request.explain(), readRequest.explain());
        assertEquals(request.query(), readRequest.query());
        assertEquals(request.rewrite(), readRequest.rewrite());
        assertEquals(request.shardId(), readRequest.shardId());
        BytesStreamOutput output = new BytesStreamOutput();
        output.setVersion(Version.V_5_0_0);
        readRequest.writeTo(output);
        assertEquals(output.bytes().toBytesRef(), requestBytes.toBytesRef());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:ShardValidateQueryRequestTests.java

示例12: createTermQuery

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
private static TermQueryBuilder createTermQuery(String name, Object text, Float boost) {
  if (isNotNull(boost)) {
    return QueryBuilders.termQuery(name, text).boost(boost);
  } else {
    return QueryBuilders.termQuery(name, text);
  }
}
 
开发者ID:project-sunbird,项目名称:sunbird-utils,代码行数:8,代码来源:ElasticSearchUtil.java

示例13: testForClient

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
@Test
public void testForClient() throws Exception {
    QueryBuilder qb = QueryBuilders.termQuery(
            "name",
            "kimchy"
    );
    client.prepareSearch().setQuery(qb).execute().actionGet();
}
 
开发者ID:felayman,项目名称:elasticsearch-full,代码行数:9,代码来源:TermQueryDemo.java

示例14: eq

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
private static QueryBuilder eq(String fieldName, Object value) {
  if (value == null) {
    // Field must not exist.
    return QueryBuilders.boolQuery()
        .mustNot(QueryBuilders.existsQuery(fieldName));
  }

  return QueryBuilders.termQuery(fieldName, value);
}
 
开发者ID:pukkaone,项目名称:odata-spring-boot-starter,代码行数:10,代码来源:ElasticsearchExpressionVisitor.java

示例15: createTestAggregatorBuilder

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
@Override
protected FilterAggregationBuilder createTestAggregatorBuilder() {
    FilterAggregationBuilder factory = new FilterAggregationBuilder(randomAsciiOfLengthBetween(1, 20),
            QueryBuilders.termQuery(randomAsciiOfLengthBetween(5, 20), randomAsciiOfLengthBetween(5, 20)));
    // NORELEASE make RandomQueryBuilder work outside of the
    // AbstractQueryTestCase
    // builder.query(RandomQueryBuilder.createQuery(getRandom()));
    return factory;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:FilterTests.java


注:本文中的org.elasticsearch.index.query.QueryBuilders.termQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。