# 版本
# es版本: elasticsearch:7.12.1
# kibana版本: kibana:7.12.1 (如果需要)
# ik版本: 7.12.1

# docker创建服务需要注意网关设置
# linux创建服务需要注意
# 参考:https://blog.csdn.net/m0_50287279/article/details/131819482

# 可以获取当前服务器是否创建好
curl 127.0.0.1:9200

# linux安装要确认好是否提供外部服务


######################################################################
# 创建索引

## 构建脚本
PUT /udi/
{
  "mappings": {
    "properties": {
      "id": {
        "type": "long"
      },
      "companyName": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "productFactoryCode": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "brandName": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "productName": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "specification": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "model": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      }
    }
  }
}

## 查询索引结构
GET /udi/_mapping


################################################################################

## 查询企业名称
POST /udi/_search
{
  "query": {
    "match": {
      "companyName": ""
    }
  }
}

## 查询出厂编码
POST /udi/_search
{
  "query": {
    "match": {
      "productFactoryCode": ""
    }
  }
}

## 查询脚本
POST /udi/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "companyName": "大博医疗"
          }
        },
        {
          "term": {
            "companyName": "大博医疗"
          }
        },
        {
          "match": {
            "productFactoryCode": "09A221013"
          }
        },
        {
          "term": {
            "productFactoryCode": "09A221013"
          }
        }
      ]
    }
  },
  "_source": ["companyName","productFactoryCode"]
}

## 查询脚本
POST /udi/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "productName": "/"
          }
        },
        {
          "match": {
            "brandName": "大博医疗"
          }
        },
        {
          "match": {
            "specification": "RHQ11"
          }
        },
        {
          "match": {
            "model": "RHQ11"
          }
        }
      ]
    }
  },
  "_source": ["productName","brandName","specification","model"]
}

## 分词解析预测
POST _analyze
{
  "analyzer": "ik_smart",
  "text": ["大博医疗"]
}


## 查询总数
GET /udi/_count