参考:

https://www.elastic.co/guide/en/elasticsearch/reference/1.7/mapping-nested-type.html

https://stackoverflow.com/questions/31829654/elastic-search-nested-multimatch-query

https://www.elastic.co/guide/en/elasticsearch/reference/5.6/nested.html

Note: changing an object type to nested type requires reindexing.

The nested object fields can also be automatically added to the immediate parent by setting include_in_parent to true, and also included in the root object by setting include_in_root to true.

Nested docs will also automatically use the root doc _all field.

//-------------------------创建索引--------------------------
--------------http://172.19.12.249:9200/indextest0121/_search
{
"mappings": {
"my_type": {
"properties": {
"sasj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"lasj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"xasj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"pasj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"zxxgsj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"saryxx": {
"type": "nested",
"include_in_parent":true,
"include_in_root":true
},
"wp": {
"type": "nested",
"include_in_parent" : true,
"include_in_root":true,
"properties": {
"zxxgsj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
}
},
"rqxx": {
"type": "nested",
"include_in_parent":true,
"include_in_root":true,
"properties": {
"jrsj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"lksj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
}
}
}
}
}
} //------------------------插入文档------------------------------ { "ajbh": "A2310010920092015010163",
"ajmc": "20140609郭广瑞生产、销售伪劣产品案",
"ajlxbm": "01",
"ajlxmc": "刑事",
"ajztbm": "01",
"ajztmc": "立案",
"sabar": "王五,赵六",
"sabarzjhm": "230106197001013213,230106197201013233",
"sabadw": "231010050200",
"sabadwmc": "黑龙江牡丹江市公安局华电分局刑事侦查队",
"labar": "王五,赵六",
"labarzjhm": "230106197001013213,230106197201013233",
"labadw": "231010050200",
"labadwmc": "黑龙江牡丹江市公安局华电分局刑事侦查队",
"xabar": "王五,赵六",
"xabarzjhm": "230106197001013213,230106197201013233",
"xabadw": "231010050200",
"xabadwmc": "黑龙江牡丹江市公安局华电分局刑事侦查队",
"pabar": "王五,赵六",
"pabarzjhm": "230106197001013213,230106197201013233",
"pabardw": "231010050200",
"pabardwmc": "黑龙江牡丹江市公安局华电分局刑事侦查队",
"sasj": "2015-01-01 12:10:30",
"lasj": "2015-01-02 12:10:30",
"xasj": "2015-01-03 12:10:30",
"pasj": "2015-01-04 12:10:30",
"zxxgsj": "2015-01-04 12:10:30"
,
"saryxx": [{
"rylx": "01",
"rylxmc": "嫌疑人",
"rybh": "R2301060000000001",
"ryxm": "张三",
"ryxb": "女",
"rynl": "20",
"ryzjhm": "230106199001123141",
"ryjtzz": "哈尔滨市松北别墅区",
"rylxdh": "18011111114"
},{
"rylx": "01",
"rylxmc": "违法行为人",
"rybh": "R2301060000000001",
"ryxm": "李四",
"ryxb": "男",
"rynl": "20",
"ryzjhm": "230106199001123141",
"ryjtzz": "哈尔滨市松北别墅区",
"rylxdh": "18011111114"
}],
"wp": [{
"wpmc": "可燃气体探测器",
"wpzlbm": "01",
"wpzlmc": "赃物",
"wpzl": "1公斤",
"wpxh": "100cmX100cmX100cm",
"wpztbm": "01",
"wpztmc": "物品入库",
"wpsl": "13",
"kfxx": "牡丹江市公安局涉案财务",
"kwxx": "A-刑事案件物品存放库|第01排|第01行|第01列|",
"kgy": "库管员",
"kypzr": "于令君",
"kfgly": "牡丹江库房管理员",
"bcqx": "12个月",
"kysj": "2015-01-01 12:10:30",
"zxxgsj": "2015-01-01 12:10:30"
},{
"wpmc": "刀",
"wpzlbm": "01",
"wpzlmc": "凶器",
"wpzl": "1公斤",
"wpxh": "100cmX100cmX100cm",
"wpztbm": "01",
"wpztmc": "物品登记",
"wpsl": "13",
"kfxx": "牡丹江市公安局涉案财务",
"kwxx": "A-刑事案件物品存放库|第01排|第01行|第01列|",
"kgy": "库管员",
"kypzr": "于令君",
"kfgly": "牡丹江库房管理员",
"bcqx": "12个月",
"kysj": "2015-01-01 12:10:30",
"zxxgsj": "2015-01-01 12:10:30"
}],
"rqxx": [{
"baqmc": "办案区名称",
"shbh": "手环编号",
"fjbh": "房间编号",
"fjmc": "房间名称",
"jrsj": "2015-01-01 12:10:30",
"lksj": "2015-01-01 12:10:30",
"rqyybm": "01",
"rqyymc": "传唤",
"lqyybm": "01",
"lqyymc": "传唤结束" }]
} //---------------------------查询文档-------------------------- {
"query": {
"bool": {
"must": [
{
"match": {
"ajztmc": "立案"
}
},
{
"match": {
"ajlxmc": "刑事"
}
},
{
"range": {
"lasj": {
"gte": "2015-01-01 12:10:10",
"lte": "2016-01-01 12:10:40"
}
}
},
{
"nested": {
"path": [
"rqxx"
],
"query": {
"bool": {
"must": [
{
"match": {
"rqxx.baqmc": "办案区名称"
}
}
]
}
}
}
},
{
"nested": {
"path": [
"saryxx"
],
"query": {
"bool": {
"must": [
{
"match": {
"saryxx.rylxmc": "嫌疑人"
}
},
{
"match": {
"saryxx.ryxb": "女"
}
}
]
}
}
}
},
{
"nested": {
"path": [
"wp"
],
"query": {
"bool": {
"must": [
{
"match": {
"wp.wpzlmc": "赃物"
}
},
{
"match": {
"wp.wpztmc": "物品入库"
}
}
]
}
}
}
},
{
"multi_match": {
"query": "男",
"lenient": "true",
"fields": [
"*"
]
}
}
]
}
},
"from": 0,
"size": 100,
"sort": {
"zxxgsj": {
"order": "desc"
}
}
}
//-------------------------创建索引--------------------------
{
"mappings": {
"my_type": {
"properties": {
"ajxx": {
"type": "nested",
"include_in_parent":true,
"include_in_root":true,
"properties": {
"sasj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"lasj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"xasj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"pasj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"zxxgsj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
}
},
"saryxx": {
"type": "nested",
"include_in_parent":true,
"include_in_root":true
},
"wp": {
"type": "nested",
"include_in_parent" : true,
"include_in_root":true,
"properties": {
"zxxgsj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
}
},
"rqxx": {
"type": "nested",
"include_in_parent":true,
"include_in_root":true,
"properties": {
"jrsj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"lksj": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
}
}
}
}
}
} //------------------------插入文档------------------------------ {
"ajxx": [{
"ajbh": "A2310010920092015010163",
"ajmc": "20140609郭广瑞生产、销售伪劣产品案",
"ajlxbm": "01",
"ajlxmc": "刑事",
"ajztbm": "01",
"ajztmc": "立案",
"sabar": "王五,赵六",
"sabarzjhm": "230106197001013213,230106197201013233",
"sabadw": "231010050200",
"sabadwmc": "黑龙江牡丹江市公安局华电分局刑事侦查队",
"labar": "王五,赵六",
"labarzjhm": "230106197001013213,230106197201013233",
"labadw": "231010050200",
"labadwmc": "黑龙江牡丹江市公安局华电分局刑事侦查队",
"xabar": "王五,赵六",
"xabarzjhm": "230106197001013213,230106197201013233",
"xabadw": "231010050200",
"xabadwmc": "黑龙江牡丹江市公安局华电分局刑事侦查队",
"pabar": "王五,赵六",
"pabarzjhm": "230106197001013213,230106197201013233",
"pabardw": "231010050200",
"pabardwmc": "黑龙江牡丹江市公安局华电分局刑事侦查队",
"sasj": "2015-01-01 12:10:30",
"lasj": "2015-01-02 12:10:30",
"xasj": "2015-01-03 12:10:30",
"pasj": "2015-01-04 12:10:30",
"zxxgsj": "2015-01-04 12:10:30"
}],
"saryxx": [{
"rylx": "01",
"rylxmc": "嫌疑人",
"rybh": "R2301060000000001",
"ryxm": "张三",
"ryxb": "女",
"rynl": "20",
"ryzjhm": "230106199001123141",
"ryjtzz": "哈尔滨市松北别墅区",
"rylxdh": "18011111114"
},{
"rylx": "01",
"rylxmc": "违法行为人",
"rybh": "R2301060000000001",
"ryxm": "李四",
"ryxb": "男",
"rynl": "20",
"ryzjhm": "230106199001123141",
"ryjtzz": "哈尔滨市松北别墅区",
"rylxdh": "18011111114"
}],
"wp": [{
"wpmc": "可燃气体探测器",
"wpzlbm": "01",
"wpzlmc": "赃物",
"wpzl": "1公斤",
"wpxh": "100cmX100cmX100cm",
"wpztbm": "01",
"wpztmc": "物品入库",
"wpsl": "13",
"kfxx": "牡丹江市公安局涉案财务",
"kwxx": "A-刑事案件物品存放库|第01排|第01行|第01列|",
"kgy": "库管员",
"kypzr": "于令君",
"kfgly": "牡丹江库房管理员",
"bcqx": "12个月",
"kysj": "2015-01-01 12:10:30",
"zxxgsj": "2015-01-01 12:10:30"
},{
"wpmc": "刀",
"wpzlbm": "01",
"wpzlmc": "凶器",
"wpzl": "1公斤",
"wpxh": "100cmX100cmX100cm",
"wpztbm": "01",
"wpztmc": "物品登记",
"wpsl": "13",
"kfxx": "牡丹江市公安局涉案财务",
"kwxx": "A-刑事案件物品存放库|第01排|第01行|第01列|",
"kgy": "库管员",
"kypzr": "于令君",
"kfgly": "牡丹江库房管理员",
"bcqx": "12个月",
"kysj": "2015-01-01 12:10:30",
"zxxgsj": "2015-01-01 12:10:30"
}],
"rqxx": [{
"baqmc": "办案区名称",
"shbh": "手环编号",
"fjbh": "房间编号",
"fjmc": "房间名称",
"jrsj": "2015-01-01 12:10:30",
"lksj": "2015-01-01 12:10:30",
"rqyybm": "01",
"rqyymc": "传唤",
"lqyybm": "01",
"lqyymc": "传唤结束" }]
} //---------------------------查询文档-------------------------- {
"query": {
"bool": {
"must": [
{
"nested": {
"path": [
"ajxx"
],
"query": {
"bool": {
"must": [
{
"match": {
"ajxx.ajztmc": "立案"
}
},
{
"range": {
"ajxx.sasj": {
"gte": "2015-01-01 12:10:10",
"lte": "2016-01-01 12:10:40"
}
}
}
]
}
}
}
},
{
"nested": {
"path": [
"rqxx"
],
"query": {
"bool": {
"must": [
{ "match": {
"rqxx.baqmc": "办案区名称"
} },
{
"range": {
"rqxx.jrsj": {
"gte": "2015-01-01 12:10:10",
"lte": "2016-01-01 12:10:40"
}
}
}
]
}
}
}
},
{
"multi_match": {
"query": "男",
"lenient": "true",
"fields": [
"*"
]
}
}
]
}
}
}

elasticsearch 嵌套对象使用Multi Match Query、query_string全文检索设置的更多相关文章

  1. elasticsearch 中的Multi Match Query

    在Elasticsearch全文检索中,我们用的比较多的就是Multi Match Query,其支持对多个字段进行匹配.Elasticsearch支持5种类型的Multi Match,我们一起来深入 ...

  2. Elasticsearch Query DSL 整理总结(四)—— Multi Match Query

    目录 引言 概要 fields 字段 通配符 提升字段权重 multi_match查询的类型 best_fields 类型 dis_max 分离最大化查询 best_fields 维权使者 tie_b ...

  3. elasticsearch 嵌套对象之嵌套类型

    nested类型是一种特殊的对象object数据类型(specialised version of the object datatype ),允许对象数组彼此独立地进行索引和查询. 1. 对象数组如 ...

  4. elasticsearch嵌套对象的映射

    在es中,我们有时候可能需要映射,{ "field" : "xx" , "field01" : [] }这样格式的嵌套对象,默认情况下es会 ...

  5. elasticsearch入门使用(三) Query DSL

    Elasticsearch Reference [6.2] » Query DSL 参考官方文档 :https://www.elastic.co/guide/en/elasticsearch/refe ...

  6. Elasticsearch Query DSL 整理总结(二)—— 要搞懂 Match Query,看这篇就够了

    目录 引言 构建示例 match operator 参数 analyzer lenient 参数 Fuzziness fuzzniess 参数 什么是模糊搜索? Levenshtein Edit Di ...

  7. Elasticsearch 5.x 关于term query和match query的认识

    http://blog.csdn.net/yangwenbo214/article/details/54142786 一.基本情况 前言:term query和match query牵扯的东西比较多, ...

  8. Elasticsearch.Net 异常:[match] query doesn't support multiple fields, found [field] and [query]

    用Elasticsearch.Net检索数据,报异常: )); ElasticLowLevelClient client = new ElasticLowLevelClient(settings); ...

  9. ElasticSearch 嵌套映射和过滤器及查询

    ElasticSearch - 嵌套映射和过滤器 Because nested objects are indexed as separate hidden documents, we can’t q ...

随机推荐

  1. linux shell 指令

    一.文件比较运算符 1. e filename 如果 filename存在,则为真 如: [ -e /var/log/syslog ] 2. -d filename 如果 filename为目录,则为 ...

  2. sentinel集群docker-compose.yml配置

    redis安装 version: '3.1'services: master: image: redis container_name: redis-master ports: - 6379:6379 ...

  3. 2018-2019 2 20165203 《网络对抗技术》Exp7 网络欺诈防范

    2018-2019 2 20165203 <网络对抗技术>Exp7 网络欺诈防范 实验目的 本实践的目标理解常用网络欺诈背后的原理,以提高防范意识,并提出具体防范方法. 实验内容 (1)简 ...

  4. 北风设计模式课程---外观模式(Facade)总结

    北风设计模式课程---外观模式(Facade)总结 一.总结 一句话总结: 不仅要通过视频学,还要看别的博客里面的介绍,搜讲解,搜作用,搜实例 设计模式都是对生活的抽象,比如用户获得装备,我可以先装备 ...

  5. 单片机程序第一句ORG 0030H什么意思

    ORG是伪指令,告诉 编译 器,程序从ROM的0000开始存放程序,但是AJMP MAIN是一条无条件跳转指令,也就是说,单片机上电之后首先从0000处开始执行程序,但是,AJMP直接将程序跳转到MA ...

  6. MySQL 获取本月第一天、下个月第一天等

    select curdate(); --获取当前日期 select last_day(curdate()); --获取当月最后一天. select DATE_ADD(curdate(),interva ...

  7. 杂项-网络-DNS-IP:8.8.8.8

    ylbtech-杂项-网络-DNS-IP:8.8.8.8 8.8.8.8是一个IP地址,是Google提供的免费DNS服务器的IP地址,Google提供的另外一个免费DNS服务器的IP地址是:8.8. ...

  8. 异常的处理try-catch

    Java异常处理 Java采用的异常处理机制,是将异常处理的程序代码集中在一起, 与正常的程序代码分开,使得程序简洁.优雅,并易于维护. * 异常的处理: 抓抛模型*** 过程一 : 抛, 程序在执行 ...

  9. SPRING CLOUD微服务DEMO-上篇

    目录 1. 微服务架构 2. 远程调用方式 2.1 RPC/RMI 2.2 Http 2.3 如何选择 3. Http客户端工具 3.1 RestTemplate 4. Spring Boot 搭建项 ...

  10. JavaScript 类型浅解

    对于JavaScript 类型,可简单地概括为:相对于强类型语言来说,它是弱(松散)类型的语言:有基本类型和引用类型,他们是区别是一个有固定空间存在于栈内存中,一个没有固定空间保存在堆内存中并且在栈内 ...