http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 5950|回复: 6

[Elasticsearch] elasticsearch-短语搜索方式

[复制链接]
发表于 2018-11-27 15:18:24 | 显示全部楼层 |阅读模式
短语搜索方式

找出一个属性中的独立单词是没有问题的,但有时候想要精确匹配一系列单词或者短语 。 比如, 我们想执行这样一个查询,仅匹配同时包含 “rock” “climbing” ,并且 二者以短语 “rock climbing” 的形式紧挨着的雇员记录。
为此对 match 查询稍作调整,使用一个叫做 match_phrase 的查询:

[Shell] 纯文本查看 复制代码
GET /megacorp/employee/_search
{
    "query" : {
        "match_phrase" : {
            "about" : "rock climbing"
        }
    }
}


返回数据
[Shell] 纯文本查看 复制代码
{
   ...
   "hits": {
      "total":      1,
      "max_score":  0.23013961,
      "hits": [
         {
            ...
            "_score":         0.23013961,
            "_source": {
               "first_name":  "John",
               "last_name":   "Smith",
               "age":         25,
               "about":       "I love to go rock climbing",
               "interests": [ "sports", "music" ]
            }
         }
      ]
   }
}



[Shell] 纯文本查看 复制代码
# Delete the `megacorp` index in case it already exists
DELETE /megacorp

# Index our example documents
PUT /megacorp/employee/1
{
    "first_name" : "John",
    "last_name" :  "Smith",
    "age" :        25,
    "about" :      "I love to go rock climbing",
    "interests": [ "sports", "music" ]
}

PUT /megacorp/employee/2
{
    "first_name" :  "Jane",
    "last_name" :   "Smith",
    "age" :         32,
    "about" :       "I like to collect rock albums",
    "interests":  [ "music" ]
}

PUT /megacorp/employee/3
{
    "first_name" :  "Douglas",
    "last_name" :   "Fir",
    "age" :         35,
    "about":        "I like to build cabinets",
    "interests":  [ "forestry" ]
}

# Find all employees whose `last_name` is Smith
# and who are older than 30
GET /megacorp/employee/_search
{
    "query" : {
        "filtered" : {
            "filter" : {
                "range" : {
                    "age" : { "gt" : 30 }
                }
            },
            "query" : {
                "match" : {
                    "last_name" : "smith"
                }
            }
        }
    }
}

# Find all employees who enjoy "rock" or "climbing"
GET /megacorp/employee/_search
{
    "query" : {
        "match" : {
            "about" : "rock climbing"
        }
    }
}

# Find all employees who enjoy "rock climbing"
GET /megacorp/employee/_search
{
    "query" : {
        "match_phrase" : {
            "about" : "rock climbing"
        }
    }
}

# Find all employees who enjoy "rock climbing"
# and highlight the matches
GET /megacorp/employee/_search
{
    "query" : {
        "match_phrase" : {
            "about" : "rock climbing"
        }
    },
    "highlight": {
        "fields" : {
            "about" : {}
        }
    }
}




1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2018-11-27 15:19:24 | 显示全部楼层
 楼主| 发表于 2018-11-27 15:37:40 | 显示全部楼层
[Shell] 纯文本查看 复制代码
get /megacorp/employee/_search
{
    "query":{

       "match_phrase":{
          "about":"rock climbing"   
       }
   }
}

post /megacorp/employee_search
{
   "query":{
      "name":" su fei yan wei fan liu zhao li tian ming yu hui zheng"
  }
}



get /megacorp/employee/_search
{
    "query":{
        "post_name":"销售 销售代表 电话营销 电话销售 电话营销 汽车销售 "
   }
}


curl -X GET "localhost:9200/megacorp/employee/_search"


curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
{
    "query" : {
        "match_phrase" : {
            "about" : "rock climbing"
        }
    }
}
'

发表于 2018-11-27 21:18:57 | 显示全部楼层
我只是路过打酱油的。  
发表于 2018-11-27 21:19:22 | 显示全部楼层
学习喽, 学习喽, 楼主加油
发表于 2018-11-27 21:33:29 | 显示全部楼层
楼主加油,我们都看好你哦。
发表于 2018-12-16 22:23:27 | 显示全部楼层
强烈支持楼主ing……
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-12-22 19:55

© 2014-2021

快速回复 返回顶部 返回列表