aou2ouba 2017-04-01 03:57 采纳率: 0%
浏览 3777

spring-boot与elasticsearch整合时如何定义内嵌对象的分词策略

@Document(indexName = "logmodel", type = "logs", shards = 4, replicas = 1,indexStoreType="fs", refreshInterval = "-1")
public class LogES {
@Id
private String id;
private String itcode;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String ip;
private String ad_type;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String telephone;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String mobile;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String email;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String firstname;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String firstnameen;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String boss;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String position;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String organization;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String country;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String cityname;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String givenname;
private String employeeNumber;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String employeetype;
private boolean ismanager;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String bossname;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String bigboss;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String bigbossname;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String enterprise;
@JsonFormat (shape = JsonFormat.Shape.STRING, pattern ="yyyy-MM-dd'T'hh:mm:ss.SSS'Z'")
private Date dt;
private String dev_platform;
private String app_version;
private String dev_version;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String dev_info;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String dev_imei;
@Field(type = FieldType.String,index = FieldIndex.not_analyzed)
private String func;
@Field( type = FieldType.Auto)
private Object content;
private CochatResponseEntity cochatResponseEntity;
比如怎么设置content对象内部字段的分词策略,如:@Field(type = FieldType.String,index = FieldIndex.not_analyzed)

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-05 16:12
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    在Spring Boot和Elasticsearch整合时,为了定义内嵌对象的分词策略,你可以使用@Field注解。以下是一个示例:

    首先,在你的实体类中定义一个名为content的对象,它将包含你想要分词的内容。

    public class LogES {
        ...
        
        @Field(type = FieldType.String)
        private Content content;
    }
    

    然后,在你的配置文件(例如application.propertiesapplication.yml)中添加@Field注解以指定内容的分词策略。

    # spring boot configuration file
    es.index.field.analyzer.name=ik_max_word
    es.index.field.splitter.type=whitespace
    

    在这个例子中,我们使用了ik_max_word作为内容的分词器,并且设置了splitter.typewhitespace,这意味着我们将使用最大词频分词算法来分割单词,同时保持单词之间的空白字符。

    请注意,你需要根据实际需求调整这些参数。例如,如果您的数据非常大并且您希望最小化内存消耗,您可以尝试使用ik_smart或者ik_smart_snowball作为分词器。

    此外,如果您需要更复杂的分词策略,请考虑使用Elasticsearch的官方插件如solrkibana,它们提供了更多高级功能,如多语言支持、自定义分词器等。

    评论

报告相同问题?