|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
分类:
bdv025-elk
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通