elasticsearch nested嵌套查询
关于es查询dsl的filter与must,term与match的区别https://blog.csdn.net/PacosonSWJTU/article/details/106751760嵌套对象查询https://www.elastic.co/guide/cn/elasticsearch/guide/2.x/nested-query.html创建索引put localhost:9200/pdi
·
关于es查询dsl的filter与must,term与match的区别
关于es查询dsl的filter与must,term与match的区别_PacosonSWJTU的博客-CSDN博客_es must和filter
嵌套对象查询
嵌套对象查询 | Elasticsearch: 权威指南 | Elastic
多条件嵌套查询:elasticSearch多条件高级检索语句,包含多个must、must_not、should嵌套示例,并考虑nested对象的特殊检索 - 近朱朱者赤 - 博客园
创建索引
put localhost:9200/pdi_cust , 注意 PUB_CUST_LABEL 字段分词了。 es7 不支持type ,所以 无需指定type。
{
"mappings" :{
"properties":{
"RCRD_ID":{
"type":"keyword"
}
, "BUSI_CODE":{
"type":"keyword"
}
, "STATE":{
"type":"keyword"
}
, "LOANS":{
"type":"nested"
, "properties" :{
"LOAN_NUM":{
"type":"keyword"
}
, "PUB_CUST_LABEL":{
"type":"text"
}
, "DATA_SRC":{
"type":"keyword"
}
, "CUST_NUM": {
"type":"keyword"
}
, "LOAN_BAL_SUM":{
"type":"double"
}
, "OVD_MONEY_SUM": {
"type": "double"
}
}
}
}
}
}
嵌套查询
使用 filter+term实现精确匹配不计分查询
// dsl
{
"_source":["RCRD_ID", "STATE", "BUSI_CODE"]
, "query":{
"bool":{
"filter":[
{
"term":{
"STATE":"PDOS"
}
}
, {
"nested":{
"path":"LOANS"
, "query":{
"bool":{
"filter":[
{
"term": {
"LOANS.LOAN_NUM": "LOAN_NUM_01"
}
}
]
}
}
, "inner_hits": {
}
}
}
]
}
}
}
// 查询结果
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.0,
"hits": [
{
"_index": "pdi_cust",
"_type": "_doc",
"_id": "tr_rd_01",
"_score": 0.0,
"_source": {
"RCRD_ID": "tr_rd_01",
"STATE": "PDOS",
"BUSI_CODE": "pdi"
},
"inner_hits": {
"LOANS": {
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.0,
"hits": [
{
"_index": "pdi_cust",
"_type": "_doc",
"_id": "tr_rd_01",
"_nested": {
"field": "LOANS",
"offset": 0
},
"_score": 0.0,
"_source": {
"CUST_NUM": "CUST_NUM_01",
"DATA_SRC": "VALD",
"LOAN_BAL_SUM": "1111",
"LOAN_NUM": "LOAN_NUM_01",
"OVD_MONEY_SUM": "1111",
"PUB_CUST_LABEL": "张三 李四 王五"
}
}
]
}
}
}
}
]
}
}
更多推荐
已为社区贡献6条内容
所有评论(0)