Search in sources :

Example 11 with SearchModule

use of org.opensearch.search.SearchModule in project OpenSearch by opensearch-project.

the class AggregatorFactoriesBuilderTests method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    // register aggregations as NamedWriteable
    SearchModule searchModule = new SearchModule(Settings.EMPTY, emptyList());
    namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    namedXContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) Before(org.junit.Before)

Example 12 with SearchModule

use of org.opensearch.search.SearchModule in project OpenSearch by opensearch-project.

the class AggregatorFactoriesTests method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    Settings settings = Settings.builder().put("node.name", AbstractQueryTestCase.class.toString()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
    xContentRegistry = new NamedXContentRegistry(new SearchModule(settings, emptyList()).getNamedXContents());
}
Also used : SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) Settings(org.opensearch.common.settings.Settings) AbstractQueryTestCase(org.opensearch.test.AbstractQueryTestCase)

Example 13 with SearchModule

use of org.opensearch.search.SearchModule in project ml-commons by opensearch-project.

the class AnomalyLocalizationInputTests method testXContentMissingAnomalyStartFilter.

@Test
public void testXContentMissingAnomalyStartFilter() throws Exception {
    AnomalyLocalizationInput input = new AnomalyLocalizationInput("indexName", Arrays.asList("attribute"), Arrays.asList(AggregationBuilders.max("max").field("field")), "@timestamp", 0L, 10L, 1L, 2, Optional.empty(), Optional.empty());
    XContentBuilder builder = XContentFactory.jsonBuilder();
    builder = input.toXContent(builder, null);
    String json = Strings.toString(builder);
    XContentParser parser = XContentType.JSON.xContent().createParser(new NamedXContentRegistry(new SearchModule(Settings.EMPTY, Collections.emptyList()).getNamedXContents()), null, json);
    parser.nextToken();
    AnomalyLocalizationInput newInput = AnomalyLocalizationInput.parse(parser);
    assertEquals(input, newInput);
}
Also used : SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser) Test(org.junit.Test)

Example 14 with SearchModule

use of org.opensearch.search.SearchModule in project ml-commons by opensearch-project.

the class AnomalyLocalizationInputTests method testXContentFullObject.

@Test
public void testXContentFullObject() throws Exception {
    AnomalyLocalizationInput input = new AnomalyLocalizationInput("indexName", Arrays.asList("attribute"), Arrays.asList(AggregationBuilders.max("max").field("field"), AggregationBuilders.min("min").field("field")), "@timestamp", 0L, 10L, 1L, 2, Optional.of(3L), Optional.of(QueryBuilders.matchAllQuery()));
    XContentBuilder builder = XContentFactory.jsonBuilder();
    builder = input.toXContent(builder, null);
    String json = Strings.toString(builder);
    XContentParser parser = XContentType.JSON.xContent().createParser(new NamedXContentRegistry(new SearchModule(Settings.EMPTY, Collections.emptyList()).getNamedXContents()), null, json);
    parser.nextToken();
    AnomalyLocalizationInput newInput = AnomalyLocalizationInput.parse(parser);
    assertEquals(input, newInput);
}
Also used : SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser) Test(org.junit.Test)

Example 15 with SearchModule

use of org.opensearch.search.SearchModule in project OpenSearch by opensearch-project.

the class InnerHitBuilderTests method init.

@BeforeClass
public static void init() {
    SearchModule searchModule = new SearchModule(Settings.EMPTY, emptyList());
    namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) BeforeClass(org.junit.BeforeClass)

Aggregations

SearchModule (org.opensearch.search.SearchModule)31 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)20 NamedXContentRegistry (org.opensearch.common.xcontent.NamedXContentRegistry)19 BeforeClass (org.junit.BeforeClass)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)6 NamedWriteableAwareStreamInput (org.opensearch.common.io.stream.NamedWriteableAwareStreamInput)6 StreamInput (org.opensearch.common.io.stream.StreamInput)5 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)5 XContentParser (org.opensearch.common.xcontent.XContentParser)5 BytesStreamOutput (org.opensearch.common.io.stream.BytesStreamOutput)4 Version (org.opensearch.Version)3 Settings (org.opensearch.common.settings.Settings)3 IndicesModule (org.opensearch.indices.IndicesModule)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Before (org.junit.Before)2 InputStreamStreamInput (org.opensearch.common.io.stream.InputStreamStreamInput)2 User (org.opensearch.commons.authuser.User)2 SearchPlugin (org.opensearch.plugins.SearchPlugin)2 AsynchronousSearchContextId (org.opensearch.search.asynchronous.context.AsynchronousSearchContextId)2