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
}