搜索的相关性Relevance
- 搜索是用户和搜索引擎的对话
- 用户关心的是搜索结果的相关性
- 是否可以找到所有相关的内容
- 有多少不相关的内容被返回了
- 文档的打分是否合理
- 结合业务需求,平衡结果排名
Page Rank算法
- 不仅仅是内容
- 更重要的是内容的可信度
衡量相关性
- Information Retrieval
- Precision (查准率) -尽可能返回较少的无关文档
- Recall (查全率) -尽量返回较多的相关文档
- Ranking -是否能够按照相关度进行排序?
指定字段
查询出指定字段(title)值为2012的数据
GET /movies/_search?q=2012&df=title
{
"profile":"true"
}
GET /movies/_search?q=title:2012
{
"profile" :"true"
}
泛查询
查询出任意字段值为2012的数据
GET /movies/_search?q=2012
{
"profile": "true"
}
Term and Phrase
- Beautiful Mind等效于Beautiful OR Mind
- “Beautiful Mind”,等效于Beautiful AND Mind。Phrase 查询,还要求前后顺序保持一致
GET /movies/_search?q=title:"Beautiful Mind"
{
"profile":"true"
}
分组查询
GET /movies/_search?q=title:(Beautiful Mind)
{
"profile":"true"
}
必须包含Beautiful和Mind
GET /movies/_search?q=title:(Beautiful AND Mind)
{
"profile":"true"
}
必须包含Beautiful不包含Mind
GET /movies/_search?q=title:(Beautiful NOT Mind)
{
"profile":"true"
}
范围查询
年份大于1980
GET /movies/_search?q=year:>=1980
{
"profile":"true"
}
通配符查询
- ?代表1个字符,*代表0个或多个字符
- title:mi?d
- title:be*
查询表达式——Match
GET /comments/_ doc/_search
{
"query":{
"match":{
"comment" : "Last Christmas"
}
}
}
GET /comments/_ doc/_search
{
"query":{
"match":{
"query":"Last Christmas",
"operator" "AND"
}
}
}
}
短语搜索——Match Phrase
GET /comments/_doc/_search
{
"query":{
"match_ phrase":{
"comment": {
//字符按照下列顺序出现
"query" "Song Last Chrismas"
//中间可以出现其他字符
"slop": 1
}
}
}
}
Simple Query String Query
- 类似 Query String,但是会忽略错误的语法,同时只支持部分查询语法
- 不支持AND OR NOT,会当作字符串处理.
- Term 之间默认的关系是OR,可以指定Operator
- 支持部分逻辑
- +替代AND
- | 替代OR
- -替代NOT