Search in sources :

Example 21 with MoreLikeThisQueryBuilder

use of org.elasticsearch.index.query.MoreLikeThisQueryBuilder in project elasticsearch by elastic.

the class ContextAndHeaderTransportIT method testThatMoreLikeThisQueryMultiTermVectorRequestContainsContextAndHeaders.

public void testThatMoreLikeThisQueryMultiTermVectorRequestContainsContextAndHeaders() throws Exception {
    transportClient().prepareIndex(lookupIndex, "type", "1").setSource(jsonBuilder().startObject().field("name", "Star Wars - The new republic").endObject()).get();
    transportClient().prepareIndex(queryIndex, "type", "1").setSource(jsonBuilder().startObject().field("name", "Jar Jar Binks - A horrible mistake").endObject()).get();
    transportClient().prepareIndex(queryIndex, "type", "2").setSource(jsonBuilder().startObject().field("name", "Star Wars - Return of the jedi").endObject()).get();
    transportClient().admin().indices().prepareRefresh(lookupIndex, queryIndex).get();
    MoreLikeThisQueryBuilder moreLikeThisQueryBuilder = QueryBuilders.moreLikeThisQuery(new String[] { "name" }, null, new Item[] { new Item(lookupIndex, "type", "1") }).minTermFreq(1).minDocFreq(1);
    SearchResponse searchResponse = transportClient().prepareSearch(queryIndex).setQuery(moreLikeThisQueryBuilder).get();
    assertNoFailures(searchResponse);
    assertHitCount(searchResponse, 1);
    assertRequestsContainHeader(MultiTermVectorsRequest.class);
}
Also used : Item(org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item) MoreLikeThisQueryBuilder(org.elasticsearch.index.query.MoreLikeThisQueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

MoreLikeThisQueryBuilder (org.elasticsearch.index.query.MoreLikeThisQueryBuilder)21 SearchResponse (org.elasticsearch.action.search.SearchResponse)18 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)17 Item (org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item)16 ArrayList (java.util.ArrayList)5 CreateIndexRequestBuilder (org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder)5 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)5 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 Client (org.elasticsearch.client.Client)1