elasticsearch7.10.0 常用 api

GET /_cat/plugins

# 查看全部索引
GET /_cat/indices

# 查看指定索引
GET /product_summary

# 删除
DELETE /product_summary

# 创建
PUT /product_summary

# 设置mapping
PUT /product_summary/_mapping
{
  "properties" : {
    "productId": {
      "type": "long"
    },
    "brandName": {
      "type": "text",
      "analyzer": "ik_smart"
    },
    "model": {
      "type": "text",
      "analyzer": "ik_smart"
    },
    "categoryName": {
      "type": "text",
      "analyzer": "ik_smart"
    },
    "categoryAttr": {
      "type": "text",
      "analyzer": "ik_smart"
    },
    "unit": {
      "type": "text"
    },
    "color": {
      "type": "text",
      "analyzer": "ik_smart"
    },
    "summary": {
      "type": "text",
      "analyzer": "ik_smart"
    }
  }
}

# 查询所有数据
GET /product_summary/_search
{
  
}

# 分词器-whitespace
GET /product_summary/_analyze
{
  "analyzer": "whitespace",
  "text": "delixi 德力西"
}

# 分词器-ik_smart 最小切分(粒度大)
GET /product_summary/_analyze
{
  "analyzer": "ik_smart",
  "text": "delixi 德力西"
}

# term - 不分词
GET /product_summary/_search
{
  "query":{
	    "term":{
	      "brandName":"delixi"
		}
	}
}

# match-分词-brandName
GET /product_summary/_search
{
  "query": {
    "match": {
      "brandName": "delixi 德力西"
    }
  },
  "highlight": {
    "fields": {
      "brandName": {}
    }
  },
  "size": 2
}

# match-分词-model
GET /product_summary/_search
{
  "query": {
    "match": {
      "model": "hr6-401/31 400a"
    }
  },
  "highlight": {
    "fields": {
      "model": {}
    }
  },
  "size": 2
}

# match-分词-多条件
GET /product_summary/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "brandName": {"query": "delixi 德力西", "boost": 4}
          }
        },
        {
          "match": {
            "model": {"query": "hr6-400/31 400a", "boost": 5}
          }
        }
      ],
      "should": [
        {
          "match": {
            "categoryName": {"query": "隔离开关 中低压配电", "boost": 1}
          }
        },
        {
          "match": {
            "categoryAttr": {"query": "26027-38-3 100g/瓶", "boost": 3}
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {
      "brandName": {},
      "model": {},
      "categoryName": {},
      "categoryAttr": {}
    }
  },
  "size": 2
}

# 更新mapping
PUT /product_summary/_mapping
{
  "properties" : {
    "productId": {
      "type": "long"
    },
    "brandName": {
      "type": "text",
      "analyzer": "ik_smart"
    },
    "model": {
      "type": "text",
      "fields": {
          "raw": {
            "type": "text",
            "analyzer": "keyword",
            "term_vector": "yes"
          }
      }
    },
    "categoryName": {
      "type": "text",
      "analyzer": "ik_smart"
    },
    "categoryAttr": {
      "type": "text",
      "analyzer": "ik_smart"
    },
    "unit": {
      "type": "text"
    },
    "color": {
      "type": "text",
      "analyzer": "ik_smart"
    },
    "summary": {
      "type": "text",
      "analyzer": "ik_smart"
    }
  }
}

# like-近文本相似度
GET /product_summary/_search
{
  "query": {
    "more_like_this": {
      "fields": ["model"],
      "like": ["hr6-401/31", "400a"],
      "min_doc_freq": 1,
      "min_term_freq": 1
    }
  },
  "highlight": {
    "fields": {
      "model": {}
    }
  },
  "size": 2
}


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值