springboot ElasticSearch

		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
            <version>2.3.1.RELEASE</version>
        </dependency>
spring:
  elasticsearch:
    rest:
      uris: 127.0.0.1
      username: elastic
      password: elastic
@EnableElasticsearchRepositories(basePackages = "com.demo.repository")

@Repository
public interface ApiRepository extends ElasticsearchRepository<ESEntity, String>{
}

@Data
@Document(indexName = Constants.INDEX_NAME)
public class ESApiCallRecordEntity implements Serializable {

	@Id
    private String id;
    
    @Field(type = FieldType.Integer)
    private Integer apiInfoId;

    private String apiName;
    
  	@Field(type = FieldType.Keyword)
    private String apiType;

    @Field(type = FieldType.Keyword)
    private String method;

    @Field(type = FieldType.Integer)
    private Integer dataSourceId;

    @Field(type = FieldType.Keyword)
    private String dataSourceType;

    private String dataSourceName;

    private String dataSourceTable;
    
    @Field(type = FieldType.Keyword)
    private String callStatus;


    @Field(type = FieldType.Integer)
    private Integer success;

    private String errorLog;

    @Field(type = FieldType.Integer)
    private Integer userId;

    /@Field(type = FieldType.Date_Nanos)
    private Long callDate;

    @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || yyyy/MM/dd HH:mm:ss|| yyyy/MM/dd ||epoch_millis")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createdAt;

    @Field(type = FieldType.Integer)
    private Integer duration;


    private static final Long serialVersionUID = 1L;






@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@Slf4j
public class ApiCallRecordRepositoryTest {

    @Autowired
    private ApiRepository apiRepository;

    /**
     * 测试新增
     */
   @Test
    public void save() {
        ESEntity esEntity = new ESEntity();
        esEntity.setApiInfoId(1);
        esEntity.setCallStatus("222");
        esEntity.setErrorLog("3333");
        esEntity.setUserId(1);
        esEntity.setCallDate(System.currentTimeMillis());
        esEntity.setDuration(333);
        ESEntity save = apiRepository.save(esEntity);
        log.info("【save】= {}", save);
    }

}
posted @ 2020-07-15 10:47  ytsee  阅读(57)  评论(0)    收藏  举报