zoukankan      html  css  js  c++  java
  • 基于词项和基于全文的搜索


    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"
        }
      }
    }
    
  • 相关阅读:
    zr#955 折纸
    zr#954 分组
    p2513 [HAOI2009]逆序对数列
    p4161 [SCOI2009]游戏
    p4593 [TJOI2018]教科书般的亵渎
    622FThe Sum of the k-th Powers
    spoj1811 LCS
    后缀自动机
    p5342 [TJOI2019]甲苯先生的线段树
    p5339 [TJOI2019]唱、跳、rap和篮球
  • 原文地址:https://www.cnblogs.com/sanduzxcvbnm/p/14518672.html
Copyright © 2011-2022 走看看