基于词项和基于全文的搜索
DELETE products
PUT products
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
}
}
POST /products/_bulk
{ "index": { "_id": 1 }}
{ "productID" : "XHDK-A-1293-#fJ3","desc":"iPhone" }
{ "index": { "_id": 2 }}
{ "productID" : "KDKE-B-9947-#kL5","desc":"iPad" }
{ "index": { "_id": 3 }}
{ "productID" : "JODL-X-1937-#pV7","desc":"MBP" }
GET /products
POST /products/_search
{
"query": {
"term": {
"desc": {
//"value": "iPhone" # 查询不出来,因为经过分词后是小写的了
"value":"iphone" # 可以查询出来
}
}
}
}
POST /products/_search
{
"query": {
"term": {
"desc.keyword": {
//"value": "iPhone" # 可以查询出来,keyword表示精确查找
//"value":"iphone" # 查询不出来
}
}
}
}
POST /products/_search
{
"query": {
"term": {
"productID": {
"value": "XHDK-A-1293-#fJ3" # 查询不出来
}
}
}
}
POST /products/_search
{
//"explain": true, # 显示详细的查询经过
"query": {
"term": {
"productID.keyword": {
"value": "XHDK-A-1293-#fJ3" # 可以查询出来
}
}
}
}
POST /products/_search
{
"explain": true,
"query": {
"constant_score": {
"filter": {
"term": {
"productID.keyword": "XHDK-A-1293-#fJ3"
}
}
}
}
}
PUT groups
{
"mappings": {
"properties": {
"names": {
"type": "text",
"position_increment_gap": 0
}
}
}
}
GET groups/_mapping
POST groups/_doc
{
"names": [
"John Water",
"Water Smith"
]
}
# 可以查询出来数据
POST groups/_search
{
"query": {
"match_phrase": {
"names": {
"query": "Water Water",
"slop": 100
}
}
}
}
# 可以查询出来数据
POST groups/_search
{
"query": {
"match_phrase": {
"names": "Water Smith"
}
}
}