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


Java MappedFieldType.setIndexOptions方法代码示例

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


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

示例1: testBuild

import org.elasticsearch.index.mapper.MappedFieldType; //导入方法依赖的package包/类
public void testBuild() throws IOException {
    Directory dir = new RAMDirectory();
    try (IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())))) {
        writer.commit();
    }
    SearchContext searchContext = mockSearchContext();
    try (IndexReader reader = DirectoryReader.open(dir)) {
        when(searchContext.getQueryShardContext().getIndexReader()).thenReturn(reader);
        MappedFieldType numberFieldType =
            new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
        MappedFieldType keywordFieldType =
            new KeywordFieldMapper.KeywordFieldType();
        for (MappedFieldType fieldType : new MappedFieldType[] {numberFieldType, keywordFieldType}) {
            fieldType.setName("field");
            fieldType.setHasDocValues(true);
            when(searchContext.getQueryShardContext().fieldMapper("field")).thenReturn(fieldType);
            CollapseBuilder builder = new CollapseBuilder("field");
            CollapseContext collapseContext = builder.build(searchContext);
            assertEquals(collapseContext.getFieldType(), fieldType);

            fieldType.setIndexOptions(IndexOptions.NONE);
            collapseContext = builder.build(searchContext);
            assertEquals(collapseContext.getFieldType(), fieldType);

            fieldType.setHasDocValues(false);
            SearchContextException exc = expectThrows(SearchContextException.class, () -> builder.build(searchContext));
            assertEquals(exc.getMessage(), "cannot collapse on field `field` without `doc_values`");

            fieldType.setHasDocValues(true);
            builder.setInnerHits(new InnerHitBuilder());
            exc = expectThrows(SearchContextException.class, () -> builder.build(searchContext));
            assertEquals(exc.getMessage(),
                "cannot expand `inner_hits` for collapse field `field`, " +
                    "only indexed field can retrieve `inner_hits`");
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:CollapseBuilderTests.java

示例2: testTermQuery

import org.elasticsearch.index.mapper.MappedFieldType; //导入方法依赖的package包/类
public void testTermQuery() {
    MappedFieldType ft = createDefaultFieldType();
    ft.setName("field");
    ft.setIndexOptions(IndexOptions.DOCS);
    assertEquals(new TermQuery(new Term("field", "foo")), ft.termQuery("foo", null));

    ft.setIndexOptions(IndexOptions.NONE);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
            () -> ft.termQuery("bar", null));
    assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:TextFieldTypeTests.java

示例3: testTermsQuery

import org.elasticsearch.index.mapper.MappedFieldType; //导入方法依赖的package包/类
public void testTermsQuery() {
    MappedFieldType ft = createDefaultFieldType();
    ft.setName("field");
    ft.setIndexOptions(IndexOptions.DOCS);
    List<BytesRef> terms = new ArrayList<>();
    terms.add(new BytesRef("foo"));
    terms.add(new BytesRef("bar"));
    assertEquals(new TermInSetQuery("field", terms),
            ft.termsQuery(Arrays.asList("foo", "bar"), null));

    ft.setIndexOptions(IndexOptions.NONE);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
            () -> ft.termsQuery(Arrays.asList("foo", "bar"), null));
    assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:TextFieldTypeTests.java

示例4: testRegexpQuery

import org.elasticsearch.index.mapper.MappedFieldType; //导入方法依赖的package包/类
public void testRegexpQuery() {
    MappedFieldType ft = createDefaultFieldType();
    ft.setName("field");
    ft.setIndexOptions(IndexOptions.DOCS);
    assertEquals(new RegexpQuery(new Term("field","foo.*")),
            ft.regexpQuery("foo.*", 0, 10, null, null));

    ft.setIndexOptions(IndexOptions.NONE);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
            () -> ft.regexpQuery("foo.*", 0, 10, null, null));
    assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:TextFieldTypeTests.java

示例5: testFuzzyQuery

import org.elasticsearch.index.mapper.MappedFieldType; //导入方法依赖的package包/类
public void testFuzzyQuery() {
    MappedFieldType ft = createDefaultFieldType();
    ft.setName("field");
    ft.setIndexOptions(IndexOptions.DOCS);
    assertEquals(new FuzzyQuery(new Term("field","foo"), 2, 1, 50, true),
            ft.fuzzyQuery("foo", Fuzziness.fromEdits(2), 1, 50, true));

    ft.setIndexOptions(IndexOptions.NONE);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
            () -> ft.fuzzyQuery("foo", Fuzziness.fromEdits(2), 1, 50, true));
    assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:TextFieldTypeTests.java


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