基于词项和基于全文的搜索

基于 Term 的查询(一般为了性能可以设置参数使其不打分

elasticsearch—深入搜索

 关于 Term查询的例子

数据准备

DELETE products
PUT products
{
  "settings": {
    "number_of_shards": 1
  }
}


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"
      }
    }
  }
}

 我们输入数据的时候是大写,查询的时候使用大写查是查不出来的,stand 默认转小写 

多字段 Mapping 和 Term

elasticsearch—深入搜索

使用 keyword 进行精确匹配

POST /products/_search
{
  "explain": true,
  "query": {
    "term": {
      "productID.keyword": {
        "value": "XHDK-A-1293-#fJ3"
      }
    }
  }
}

可以看到默认有计算打分的过程

elasticsearch—深入搜索

 复合查询constact score 转换为 Filter

elasticsearch—深入搜索

POST /products/_search
{
  "explain": true,
  "query": {
    "constant_score": {
      "filter": {
        "term": {
          "productID.keyword": "XHDK-A-1293-#fJ3"
        }
      }
    }
  }
}

 elasticsearch—深入搜索

 基于全文的查询

elasticsearch—深入搜索

 elasticsearch—深入搜索

最新匹配度

elasticsearch—深入搜索

短语查询 

elasticsearch—深入搜索

 Match query 查询过程

elasticsearch—深入搜索

相关阅读

 结构化搜索

结构化数据

elasticsearch—深入搜索

 Es中的结构化搜索

elasticsearch—深入搜索

数据准备

#结构化搜索,精确匹配
DELETE products
POST /products/_bulk
{ "index": { "_id": 1 }}
{ "price" : 10,"avaliable":true,"date":"2018-01-01", "productID" : "XHDK-A-1293-#fJ3" }
{ "index": { "_id": 2 }}
{ "price" : 20,"avaliable":true,"date":"2019-01-01", "productID" : "KDKE-B-9947-#kL5" }
{ "index": { "_id": 3 }}
{ "price" : 30,"avaliable":true, "productID" : "JODL-X-1937-#pV7" }
{ "index": { "_id": 4 }}
{ "price" : 30,"avaliable":false, "productID" : "QQPX-R-3956-#aD8" }

GET products/_mapping



#对布尔值 match 查询,有算分
POST products/_search
{
  "profile": "true",
  "explain": true,
  "query": {
    "term": {
      "avaliable": true
    }
  }
}
View Code 

相关文章:

  • 2021-06-11
  • 2021-05-26
  • 2021-12-04
  • 2021-06-14
  • 2022-02-13
  • 2021-08-07
  • 2021-06-15
  • 2021-04-02
猜你喜欢
  • 2021-09-09
  • 2021-06-07
  • 2021-09-18
  • 2021-10-22
  • 2022-02-07
  • 2021-07-11
  • 2022-02-24
相关资源
相似解决方案