elasticsearch基本查询二(英文分词)term和terms查询

term和terms查询(查找zhaoliu这个人的信息)
term query会去倒排索弓|中寻找确切的term,它并不知道分词器的存在。这种查询适合keyword、numeric. date.
term:查询某个字段里含有某个关键词的文档
GET /lib3/user/_search/ { "query":{ "term": {interests": "changge"}}}
terms:查询某个字段里合有多个关键词的文档
GET /ib3/user/_search { "query":{ "terms':{ "interests": ["hejiu","changge']}}

GET /lib3/user/_search
{"query": {"term": {"name": {"value": "zhaoliu"}}}
}GET /lib3/user/_search
{"query": {"term": {"name": "zhaoliu"}}
}
{"took" : 5,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 1,"max_score" : 0.2876821,"hits" : [{"_index" : "lib3","_type" : "user","_id" : "1","_score" : 0.2876821,"_source" : {"name" : "zhaoliu","address" : "hei long jiang sheng tie ling shi","age" : 50,"birthday" : "1970-12-12","interests" : "xi buan hejiu, duanlian, lvyou"}}]}
}


 

查找兴趣爱好interests为hejiu changge的人的信息

GET /lib3/user/_search
{"query": {"terms": {"interests": ["hejiu","changge"]}}
}
{"took" : 56,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 4,"max_score" : 1.0,"hits" : [{"_index" : "lib3","_type" : "user","_id" : "5","_score" : 1.0,"_source" : {"name" : "zhangsan","address" : "bei jing chao yang qu","age" : 29,"birthday" : "1988-10-12","interests" : "xi huan tingyinyue , changge , tiaowu"}},{"_index" : "lib3","_type" : "user","_id" : "2","_score" : 1.0,"_source" : {"name" : "zhaoming","address" : "bei jing hai dian qu qing he zhen","age" : 20,"birthday" : "1998-10-12","interests" : "xi huan hejiu, duanlian, changge"}},{"_index" : "lib3","_type" : "user","_id" : "1","_score" : 1.0,"_source" : {"name" : "zhaoliu","address" : "hei long jiang sheng tie ling shi","age" : 50,"birthday" : "1970-12-12","interests" : "xi buan hejiu, duanlian, lvyou"}},{"_index" : "lib3","_type" : "user","_id" : "3","_score" : 1.0,"_source" : {"name" : "lisi","address" : "bei jing hai dian qu qing he zhen","age" : 23,"birthday" : "1998-10-12","interests" : "xi huan hejiu,duanlian, changge"}}]}
}


只要含有一个关键词的都会被查询出来总共四个人有关于hejiu changge要么changge要么hejiu 要么两者都

如果我只想取前2个人使用from:0 (表示从第一个文档开始)       size:2(取2个文档)

GET /lib3/user/_search
{"from":0,"size":2,"query": {"terms": {"interests": ["hejiu","changge"]}}
}
{"took" : 81,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 4,"max_score" : 1.0,"hits" : [{"_index" : "lib3","_type" : "user","_id" : "5","_score" : 1.0,"_source" : {"name" : "zhangsan","address" : "bei jing chao yang qu","age" : 29,"birthday" : "1988-10-12","interests" : "xi huan tingyinyue , changge , tiaowu"}},{"_index" : "lib3","_type" : "user","_id" : "2","_score" : 1.0,"_source" : {"name" : "zhaoming","address" : "bei jing hai dian qu qing he zhen","age" : 20,"birthday" : "1998-10-12","interests" : "xi huan hejiu, duanlian, changge"}}]}
}


以上查询都是没有版本号的我们要获取版本号,只需要加一个version:true

GET /lib3/user/_search
{"version": true, "query": {"terms": {"interests": ["hejiu","changge"]}}
}
{"took" : 33,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 4,"max_score" : 1.0,"hits" : [{"_index" : "lib3","_type" : "user","_id" : "5","_version" : 1,"_score" : 1.0,"_source" : {"name" : "zhangsan","address" : "bei jing chao yang qu","age" : 29,"birthday" : "1988-10-12","interests" : "xi huan tingyinyue , changge , tiaowu"}},{"_index" : "lib3","_type" : "user","_id" : "2","_version" : 1,"_score" : 1.0,"_source" : {"name" : "zhaoming","address" : "bei jing hai dian qu qing he zhen","age" : 20,"birthday" : "1998-10-12","interests" : "xi huan hejiu, duanlian, changge"}},{"_index" : "lib3","_type" : "user","_id" : "1","_version" : 1,"_score" : 1.0,"_source" : {"name" : "zhaoliu","address" : "hei long jiang sheng tie ling shi","age" : 50,"birthday" : "1970-12-12","interests" : "xi buan hejiu, duanlian, lvyou"}},{"_index" : "lib3","_type" : "user","_id" : "3","_version" : 1,"_score" : 1.0,"_source" : {"name" : "lisi","address" : "bei jing hai dian qu qing he zhen","age" : 23,"birthday" : "1998-10-12","interests" : "xi huan hejiu,duanlian, changge"}}]}
}


 
 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/576588.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Iphone开发之音频101(part 2):转换和录音

iPhone开发之音频101(Part 2):转换和录音 译者:大侠自来也 免责申明(必读!):本博客提供的所有教程的翻译原稿均来自于互联网,仅供学习交流之用,切勿进行商业传播。同时,转…

机器学习笔记(十三)——隐马尔科夫模型

一、隐马尔科夫模型 在马尔科夫模型中,每一个状态代表了一个可以观察的事件,所以,马尔科夫模型有时称为可视马尔科夫模型(visible Markov model,VMM),这在某种程度上限制了模型的适应性。在隐马…

elasticsearch基本查询三(英文分词)match查询

#match查询 #match query知道分词器的存在,会对filed进行分词操作, 然后再查询 GET /ib3/user/_search { "query":{ "match":{ "name": "zhaoliu" }} } GET /lib3/user/_search { "query":{ "match"…

solr 3.5 配置及应用(二)

在 solr 3.5 配置及应用(一) 讲过一了 solr 3.5的详细配置,本节我们讲利用solr 的客户端调用solr的应用了! 一、利用SolrJ操作solr API 使用SolrJ操作Solr会比利用httpClient来操作Solr要简单。SolrJ是封装了httpClient方法,来操作solr的API的…

elasticsearch控制返回字段查询三(英文分词)match查询

#_source指定查询返回的字段信息 #_source指定查询返回的字段信息 GET /lib3/user/_search {"from":0, "size": 2, "_source": ["address" , "name"] ,"query": {"match": {"interests": &…

通过日志恢复MSSQL数据例子

这段时间看了关于在SQL server 中通过日志和时间点来恢复数据。也看了一些网上的例子,看如何通过日志来恢复数据。 前提条件: 数据库的故障恢复改为非简单模式,去掉自动关闭和自动收缩两个选项 如果是简单模式: 类似下面的语…

最优化学习笔记(十一)——对偶问题的例子

某线性规划问题为: mincTxst.Ax≤b\min \boldsymbol{c}^T\boldsymbol{x} \\ st. \boldsymbol{Ax} \le \boldsymbol{b}这个例子和上节中的表2非对称形式的对偶关系比较接近,将上式改写为: maxxT(−c)st.xTAT≤bT\max \boldsymbol{x^T(-c)}\\ …

ElasticSearch查询返回信息根据字段排序(英文检索)

根据年龄降序排序 #排序 GET /lib3/user/_search {"query": {"match_all": {}},"sort":[{"age": {"order" :"desc"}}] } {"took" : 1,"timed_out" : false,"_shards" : {"t…

机器学习笔记(十四)——HMM估计问题和前向后向算法

一、隐马尔科夫链的第一个基本问题 估计问题:给定一个观察序列OO1O2…OT和模型u(A,B,π),如何快速地计算出给定模型u情况下,观察序列O的概率, 即P(O|u)? 二、求解观察序列的概率 其实,求解这个问题就是一个解码问题。 对于任意的状态序列Q…

windows中架设基于Apache的svn服务器

1.安装apache及svn的windows版我安装的版本是:httpd-2.2.22-win32-x86-openssl-0.9.8t.msi 和svn-win32-1.5.0.zipsvn是解压就可以了2. 解svn安装目录下\bin下的mod_authz_svn.so、mod_dav_svn.so拷贝到apache/modules下3.将 svn安装目录下\bin下的libdb44.dll拷贝到apache/bin…

ElasticSearch通配符 * 查询(英文检索)

#如果你要查询的字段信息记得不太清楚, 我们也可以使用通配符 * GET /lib3/user/_search {"from":0, "size": 2,"_source": {"includes": "addr*","excludes": ["name" , "bir*"]},"…

sqlserver agent不能启动

我启动了 event log 服务 ,就好了,不知什么原因转载于:https://www.cnblogs.com/laogao/archive/2012/03/11/2390794.html

机器学习笔记(十五)——HMM序列问题和维特比算法

一、引言 这篇blog主要讲序列问题和其解法——维特比算法。 二、HMM中的第二个基本问题 序列问题:给定一个观察序列OO1O2…OT和模型u(A,B,π),如何快速有效地选择在一定意义下”最优”的状态序列Qq1q2…qT,使得该状态序列“最好地解释”观察序列&#…

ElasticSearch范围查询(英文检索)

#根据日期范围查询 #范围查询 GET /lib3/user/_search {"query": {"range": {"birthday": {"from": "1990-10-10","to": "2020-03-15"}}} }{"took" : 24,"timed_out" : false,&qu…

(转)CDN是如何工作的?

转载自:CDN是如何工作的? CDN是互联网中使用较频繁的一种技术。你也许常听人说:“我们的网站使用了CDN技术”,但可能他们对CDN的了解并不多,也许只局限于--用了以后网站访问速度会变快。 其实,CDN的原理非常…

ElasticSearch前缀匹配查询(英文检索)

#前缀匹配查询 #前缀匹配查询 GET /lib3/user/_search {"query": {"match_phrase_prefix": {"name":{"query":"zhao"}}} }{"took" : 59,"timed_out" : false,"_shards" : {"total&quo…

机器学习笔记(十六)——EM算法概述

一、引言 按照计划,这周应该学习HMM中的第三个基本问题:参数估计问题,但是其中的内容涉及到了EM算法,所以打算先把EM算法搞定之后再去继续HMM的问题。EM算法的推导过程比较复杂,这节我只给出简述和计算公式&#xff0c…

c# 日期函数[string.Format----GetDateTimeFormats] --转载

c# 日期函数[string.Format----GetDateTimeFormats] c# 日期函数 DateTime dt DateTime.Now;Label1.Text dt.ToString();//2005-11-5 13:21:25Label2.Text dt.ToFileTime().ToString();//127756416859912816Label3.Text dt.ToFileTimeUtc().ToString();//12775670485991281…

ElasticSearch wildcard查询(英文检索)

wildcard查询 允许使用通配符*和?来进行查询 *代表0个或多个字符 工代表任意1个字符 GET /ib3/user/ search { "query": { "wildcard":{ "name": *zhao* }}} GET /ib3/user/ search { "query": { "wildcard":{ *name"…

机器学习笔记(十七)——EM算法的推导

一、Jensen 不等式 在EM算法的推导过程中,用到了数学上的Jensen不等式,这里先来介绍一下。 若Ω是有限集合{x1,x2,…,xn}{x1,x2,…,xn},而μ是Ω上的正规计数测度,则不等式的一般形式可以简单地用和式表示: φ(∑i1ng(xi)λi)≤…