Elasticsearch 学习笔记 高级查询
来源:互联网 发布:新中新dkq a16d软件 编辑:程序博客网 时间:2024/05/21 15:02
以下查询
POST 127.0.0.1:9200/book/_search
1、多条件查询
{"query":{"multi_match":{"query":"chenjie","fields":["auther","title"]}}}
{ "took": 11, "timed_out": false, "_shards": { "total": 3, "successful": 3, "skipped": 0, "failed": 0 }, "hits": { "total": 1, "max_score": 1.2029922, "hits": [ { "_index": "book", "_type": "novel", "_id": "AV8jW8WW4oF9V8mhiGCp", "_score": 1.2029922, "_source": { "word_count": "4000", "author": "chenjie", "title": "chenjie传", "publish_date": "1994-09-27" } } ] }}
2、使用AND OR
{"query":{"query_string":{"query":"(chenjie AND 入门) OR 活着 "}}}
{ "took": 10, "timed_out": false, "_shards": { "total": 3, "successful": 3, "skipped": 0, "failed": 0 }, "hits": { "total": 2, "max_score": 1.9439287, "hits": [ { "_index": "book", "_type": "novel", "_id": "1", "_score": 1.9439287, "_source": { "doc": { "title": "活着" }, "title": "活着", "word_count": 9000, "author": "余华", "publish_date": "2017-10-16" } }, { "_index": "book", "_type": "novel", "_id": "AV8i0A5k4oF9V8mhiGCh", "_score": 1.7533967, "_source": { "word_count": "1000", "author": "chenjie", "title": "Java从入门到放弃", "publish_date": "1995-08-19" } } ] }}
3、指定查询的范围
{"query":{"query_string":{"query":"(chenjie AND 入门) OR 活着 ","fields":["title","author"]}}}
结果:
{ "took": 8, "timed_out": false, "_shards": { "total": 3, "successful": 3, "skipped": 0, "failed": 0 }, "hits": { "total": 2, "max_score": 1.8134993, "hits": [ { "_index": "book", "_type": "novel", "_id": "AV8i0A5k4oF9V8mhiGCh", "_score": 1.8134993, "_source": { "word_count": "1000", "author": "chenjie", "title": "Java从入门到放弃", "publish_date": "1995-08-19" } }, { "_index": "book", "_type": "novel", "_id": "1", "_score": 1.6831388, "_source": { "doc": { "title": "活着" }, "title": "活着", "word_count": 9000, "author": "余华", "publish_date": "2017-10-16" } } ] }}
4、查询指定的列为给定条件的
{"query":{"term":{"author":"chenjie"}}}
结果:
{ "took": 6, "timed_out": false, "_shards": { "total": 3, "successful": 3, "skipped": 0, "failed": 0 }, "hits": { "total": 3, "max_score": 0.6931472, "hits": [ { "_index": "book", "_type": "novel", "_id": "AV8i0A5k4oF9V8mhiGCh", "_score": 0.6931472, "_source": { "word_count": "1000", "author": "chenjie", "title": "Java从入门到放弃", "publish_date": "1995-08-19" } }, { "_index": "book", "_type": "novel", "_id": "AV8i0JvQ4oF9V8mhiGCi", "_score": 0.47000363, "_source": { "word_count": "2000", "author": "chenjie", "title": "MySql从删库到跑路", "publish_date": "1994-09-27" } }, { "_index": "book", "_type": "novel", "_id": "AV8jW8WW4oF9V8mhiGCp", "_score": 0.47000363, "_source": { "word_count": "4000", "author": "chenjie", "title": "chenjie传", "publish_date": "1994-09-27" } } ] }}
5、范围,日期
{"query":{"range":{"publish_date":{"gt":"1990-01-01","lte":"now"}}}}
结果:
{ "took": 303, "timed_out": false, "_shards": { "total": 3, "successful": 3, "skipped": 0, "failed": 0 }, "hits": { "total": 5, "max_score": 1, "hits": [ { "_index": "book", "_type": "novel", "_id": "AV8i0JvQ4oF9V8mhiGCi", "_score": 1, "_source": { "word_count": "2000", "author": "chenjie", "title": "MySql从删库到跑路", "publish_date": "1994-09-27" } }, { "_index": "book", "_type": "novel", "_id": "AV8i0UpQ4oF9V8mhiGCj", "_score": 1, "_source": { "word_count": "8000", "author": "路遥", "title": "平凡的世界", "publish_date": "2000-01-01" } }, { "_index": "book", "_type": "novel", "_id": "AV8jW8WW4oF9V8mhiGCp", "_score": 1, "_source": { "word_count": "4000", "author": "chenjie", "title": "chenjie传", "publish_date": "1994-09-27" } }, { "_index": "book", "_type": "novel", "_id": "AV8i0A5k4oF9V8mhiGCh", "_score": 1, "_source": { "word_count": "1000", "author": "chenjie", "title": "Java从入门到放弃", "publish_date": "1995-08-19" } }, { "_index": "book", "_type": "novel", "_id": "1", "_score": 1, "_source": { "doc": { "title": "活着" }, "title": "活着", "word_count": 9000, "author": "余华", "publish_date": "2017-10-16" } } ] }}
6、filter指定列
{"query":{"bool":{"filter":{"term":{"word_count": 1000}}}}}
结果:
{ "took": 16, "timed_out": false, "_shards": { "total": 3, "successful": 3, "skipped": 0, "failed": 0 }, "hits": { "total": 1, "max_score": 0, "hits": [ { "_index": "book", "_type": "novel", "_id": "AV8i0A5k4oF9V8mhiGCh", "_score": 0, "_source": { "word_count": "1000", "author": "chenjie", "title": "Java从入门到放弃", "publish_date": "1995-08-19" } } ] }}
7、固定分数
{"query":{"constant_score":{"filter":{"match":{"author":"chenjie"}}}}}
{ "took": 30, "timed_out": false, "_shards": { "total": 3, "successful": 3, "skipped": 0, "failed": 0 }, "hits": { "total": 3, "max_score": 1, "hits": [ { "_index": "book", "_type": "novel", "_id": "AV8i0JvQ4oF9V8mhiGCi", "_score": 1, "_source": { "word_count": "2000", "author": "chenjie", "title": "MySql从删库到跑路", "publish_date": "1994-09-27" } }, { "_index": "book", "_type": "novel", "_id": "AV8jW8WW4oF9V8mhiGCp", "_score": 1, "_source": { "word_count": "4000", "author": "chenjie", "title": "chenjie传", "publish_date": "1994-09-27" } }, { "_index": "book", "_type": "novel", "_id": "AV8i0A5k4oF9V8mhiGCh", "_score": 1, "_source": { "word_count": "1000", "author": "chenjie", "title": "Java从入门到放弃", "publish_date": "1995-08-19" } } ] }}
固定分数给定分数:
{"query":{"constant_score":{"filter":{"match":{"author":"chenjie"}},"boost":2}}}
8、使用should关键字,或逻辑
{"query":{"bool":{"should":[{"match":{"author":"chenjie"}},{"match":{"title":"java"}}]}}}
结果:
{ "took": 9, "timed_out": false, "_shards": { "total": 3, "successful": 3, "skipped": 0, "failed": 0 }, "hits": { "total": 3, "max_score": 1.2533233, "hits": [ { "_index": "book", "_type": "novel", "_id": "AV8i0A5k4oF9V8mhiGCh", "_score": 1.2533233, "_source": { "word_count": "1000", "author": "chenjie", "title": "Java从入门到放弃", "publish_date": "1995-08-19" } }, { "_index": "book", "_type": "novel", "_id": "AV8i0JvQ4oF9V8mhiGCi", "_score": 0.47000363, "_source": { "word_count": "2000", "author": "chenjie", "title": "MySql从删库到跑路", "publish_date": "1994-09-27" } }, { "_index": "book", "_type": "novel", "_id": "AV8jW8WW4oF9V8mhiGCp", "_score": 0.47000363, "_source": { "word_count": "4000", "author": "chenjie", "title": "chenjie传", "publish_date": "1994-09-27" } } ] }}
9、使用must完成与逻辑
{"query":{"bool":{"must":[{"match":{"author":"chenjie"}},{"match":{"title":"java"}}]}}}
结果:
{ "took": 14, "timed_out": false, "_shards": { "total": 3, "successful": 3, "skipped": 0, "failed": 0 }, "hits": { "total": 1, "max_score": 1.2533233, "hits": [ { "_index": "book", "_type": "novel", "_id": "AV8i0A5k4oF9V8mhiGCh", "_score": 1.2533233, "_source": { "word_count": "1000", "author": "chenjie", "title": "Java从入门到放弃", "publish_date": "1995-08-19" } } ] }}
9、must + filter
{"query":{"bool":{"must":[{"match":{"author":"chenjie"}},{"match":{"title":"java"}}],"filter":{"term":{"word_count":1000}}}}}
结果:
{ "took": 6, "timed_out": false, "_shards": { "total": 3, "successful": 3, "skipped": 0, "failed": 0 }, "hits": { "total": 1, "max_score": 1.2533233, "hits": [ { "_index": "book", "_type": "novel", "_id": "AV8i0A5k4oF9V8mhiGCh", "_score": 1.2533233, "_source": { "word_count": "1000", "author": "chenjie", "title": "Java从入门到放弃", "publish_date": "1995-08-19" } } ] }}
10、must not
{"query":{"bool":{"must_not":{"term":{"author":"chenjie"}}}}}
结果:
{ "took": 9, "timed_out": false, "_shards": { "total": 3, "successful": 3, "skipped": 0, "failed": 0 }, "hits": { "total": 2, "max_score": 1, "hits": [ { "_index": "book", "_type": "novel", "_id": "AV8i0UpQ4oF9V8mhiGCj", "_score": 1, "_source": { "word_count": "8000", "author": "路遥", "title": "平凡的世界", "publish_date": "2000-01-01" } }, { "_index": "book", "_type": "novel", "_id": "1", "_score": 1, "_source": { "doc": { "title": "活着" }, "title": "活着", "word_count": 9000, "author": "余华", "publish_date": "2017-10-16" } } ] }}
阅读全文
0 0
- Elasticsearch 学习笔记 高级查询
- hive学习笔记-高级查询
- Oracle学习笔记:高级查询
- mongodb 学习笔记-高级查询
- Elasticsearch学习笔记1----常用查询操作
- Elasticsearch笔记-深入查询
- Elasticsearch笔记-过滤查询
- Elasticsearch笔记-深入查询
- oralce学习笔记之高级查询篇
- [oracle学习笔记]之三:高级查询
- Oracle 11g学习笔记--高级查询
- Elasticsearch 学习笔记 索引创建、插入、查询、修改、删除
- Elasticsearch(十)【NEST高级客户端--搜索查询】
- ElasticSearch-深入理解系列8-高级查询
- (九)ElasticSearch高级查询语法
- ElasticSearch笔记-索引与查询
- Elasticsearch API聚合查询-笔记
- ElasticSearch学习笔记
- 判断是否唯一
- 搭建及使用K8s集群 <目录>
- AutoCAD 2013 安装错误 microsoft visual C++ 2005 SP1 Redistributable Package(86)
- 从多项分布采样的Java实现
- C 数据类型
- Elasticsearch 学习笔记 高级查询
- Java四种引用包括强引用,软引用,弱引用,虚引用。
- sparkml和mllib分别实现KMeans算法
- Linux主机文件777,755,644权限详解
- 判断手机是否有虚拟按钮,获取虚拟按钮的高度
- 修改回现
- DragonBoard-410c
- MySQL Community Server 5.7.19安装指南
- Vision_数据结构_并查集