package com.bawei.es.controller;

import com.bawei.common.core.domain.R;
import com.bawei.common.core.web.domain.AjaxResult;
import com.bawei.es.service.EsIndexService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/index")
public class EsIndexController {
    @Autowired
    private EsIndexService esindexService;



    @PostMapping("/createIndex/{indexName}")
    public R createIndex(@PathVariable String indexName, @RequestBody Map<String,Object> docMsg) {
        return R.ok(esindexService.createIndex(indexName,docMsg),"索引添加成功");
    }
    @PostMapping("/deleteIndex")
    public R deleteIndex(String indexName) {
        return R.ok(esindexService.deleteIndex(indexName),"es索引删除成功");
    }

    @PutMapping("/updateIndex")
    public R updateIndex(@PathVariable String indexName,@RequestBody Map<String,Object> docMsg){
        return R.ok(esindexService.updateIndex(indexName,docMsg),"es索引修改成功");
    }

    @GetMapping("/findIndex/{indexName}")
    public R findIndex(@PathVariable String indexName) {
        return esindexService.findIndex(indexName) ? R.ok("es索引存在") : R.fail(500,"es索引不存在");
    }

    @PostMapping("/getMapping/{indexName}")
    public R getMapping(@PathVariable String indexName) {
        return R.ok(esindexService.getMapping(indexName),"索引映射存在");
    }
}
