有两个父子type,his(订单)和white(白名单),要根据条件取white表中的cwId没有出现在his表的记录(大概是用来过滤那些没有发送过短信的客户信息,然后给他们发信息)。
{
"mappings": {
"tbl_cash_apply_order_his": {
"_parent": {
"type": "tbl_cash_white"
},
"_routing": {
"required": true
},
"properties": {
"aoApplNo": {
"type": "string"
},
"aoCwId": {
"type": "string"
},
"aoOrderStatus": {
"type": "string"
},
"aoUpdateTime": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
},
"tbl_cash_white": {
"_parent": {
"type": "tbl_cash_batch"
},
"_routing": {
"required": true
},
"properties": {
"cwAlotStatus": {
"type": "string"
},
"cwBatchNo": {
"type": "string"
},
"cwCreditLimit": {
"type": "string"
},
"cwId": {
"type": "string"
},
"cwIdNo": {
"type": "string"
},
"cwName": {
"type": "string"
},
"cwPhoneNo": {
"type": "string"
},
"cwSerialNo": {
"type": "double"
},
"cwUpdateTime": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
},
"tbl_cash_batch": {
"properties": {
"btId": {
"type": "string"
},
"btNo": {
"type": "string"
},
"btUpdateTime": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"btUsefulBegin": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"btUsefulEnd": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
}
}
}
"settings": { "number_of_shards" : 1, "number_of_replicas" : 0 }然后一直没有出过问题,但是在产线部署的是3节点5分片,于是出现问题了
curl -XGET '106.75.33.233:9200/smsservice/tbl_cash_white/_search/?pretty' -H 'Content-Type: application/json' -d'
{
"query": {
"bool": {
"must_not": {
"has_child" : {
"type" : "tbl_cash_apply_order_his",
"query" : {"match_all": {}}
}
},
"must": {
"query" : {
"match_phrase" : {"cwBatchNo": "POS_2nd_20171124"}
}
},
"must": {
"query" : {
"range" : {
"cwSerialNo": {"gte": 30287,"lte": 30287}
}
}
}
}
}
}
'
命中了一个记录
仔细查看DSL和逻辑都没问题啊,怎么回事呢?
观察发现这两条有关联的记录routing值是不一样的,也就是他们有可能落在不同的分区上,是不是由于这个引起的呢?
加入分区参数(-XGET '106.75.33.233:9200/smsservice/tbl_cash_white/_search/?pretty&preference=_shards:4')发现这两条有父子联系的type记录确实位于不同的分区上,可见Elasticsearch的坑还是多啊。