|NO.Z.00018|——————————|BigDataEnd|——|Hadoop&ElasticSearch.V18|——|ELK.v18|集群|QueryDSL|全文搜索.V1|

一、全文搜索(full-text query)
### --- 全文搜索(full-text query)

~~~     全文搜索能够搜索已分析的文本字段,如电子邮件正文,商品描述等。
~~~     使用索引期间应用于字段的同一分词器处理查询字符串。全文搜索的分类很多 几个典型的如下:
二、匹配搜索
### --- 匹配搜索(match query)

~~~     # match
~~~     全文查询的标准查询,
~~~     需要指定字段名,
~~~     输入文本会进行分词,
~~~     比如"hello elasticsearch"会进行拆分为hello和elasticsearch,
~~~     然后匹配,如果字段中包含hello或者elasticsearch,或者都包含的结果都会被查询出来,
~~~     也就是说match是一个部分匹配的模糊查询。查询条件相对来说比较宽松
~~~     match queries 接收 text/numerics/dates, 对它们进行分词分析, 再组织成一个boolean查询。
~~~     可通过operator 指定bool组合操作(or、and 默认是 or )。
### --- 现在,索引库中有2部手机,1台电视;

PUT /yanqi-property
{
  "settings": {},
  "mappings": {
  "properties": {
    "title": {
    "type": "text",
    "analyzer": "ik_max_word"
    },
    "images": {
    "type": "keyword"
    },
    "price": {
    "type": "float"
    }
  }
  }
}
POST /yanqi-property/_doc/
{
  "title": "小米电视4A",
  "images": "http://image.yanqi.com/12479122.jpg",
  "price": 4288
}
POST /yanqi-property/_doc/
{
"title": "小米手机",
"images": "http://image.yanqi.com/12479622.jpg",
"price": 2699
}
POST /yanqi-property/_doc/
{
  "title": "华为手机",
  "images": "http://image.yanqi.com/12479922.jpg",
  "price": 5699
}
### --- or关系:match 类型查询,会把查询条件进行分词,然后进行查询,多个词条之间是or的关系

POST /yanqi-property/_search
{
"query":{
"match":{
"title":"小米电视4A"
}
}
}

### --- 在上面的案例中,不仅会查询到电视,而且与小米相关的都会查询到,多个词之间是or 的关系。

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 2.8330114,
    "hits" : [
      {
        "_index" : "yanqi-property",
        "_type" : "_doc",
        "_id" : "Hbu_Un0BUgLPfzc73wRt",
        "_score" : 2.8330114,
        "_source" : {
          "title" : "小米电视4A",
          "images" : "http://image.yanqi.com/12479122.jpg",
          "price" : 4288
        }
      },
      {
        "_index" : "yanqi-property",
        "_type" : "_doc",
        "_id" : "HrvAUn0BUgLPfzc7OgRO",
        "_score" : 0.52354836,
        "_source" : {
          "title" : "小米手机",
          "images" : "http://image.yanqi.com/12479622.jpg",
          "price" : 2699
        }
      }
    ]
  }
}
### --- and关系

~~~     某些情况下,我们需要更精确查找,我们希望这个关系变成and ,可以这样做:
POST /yanqi-property/_search
{"query":
{"match": {
  "title":
  {"query": "小米电视4A","operator": "and"}
}
}
}
~~~     # 输出结果:本例中,只有同时包含小米和电视的词条才会被搜索到。

{
  "took" : 7,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 2.8330114,
    "hits" : [
      {
        "_index" : "yanqi-property",
        "_type" : "_doc",
        "_id" : "Hbu_Un0BUgLPfzc73wRt",
        "_score" : 2.8330114,
        "_source" : {
          "title" : "小米电视4A",
          "images" : "http://image.yanqi.com/12479122.jpg",
          "price" : 4288
        }
      }
    ]
  }
}

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

posted on   yanqi_vip  阅读(15)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示