Es版本5.6.3
具体父子结构如下:
机构信息表(父)、机构关键词表(子)、机构专利表(子)
根据关键词查询机构,并且同时得出这些机构发表的包含有该关键词的专利数,并按照专利数进行倒序排序。
也就是查询条件同时匹配父子表,然后根据字表的数量进行排序
目前我只是实现了查询,查询语句和结果如下:
 
 
问题:
根据查询结果,我想把有15个子元素的机构排在有三个子元素的机构上方,DSL语句中排序那里应该怎么写?
 
 
 
 
 
 
 
																
																																
															
														具体父子结构如下:
机构信息表(父)、机构关键词表(子)、机构专利表(子)
PUT /unit_idx
{
    "mappings" : {
        "unit_info": {
            "dynamic": false,
            "properties": {
                "unit_id":{
                    "type":"keyword"        
                },
                "unit_name": {
                    "type": "text"
                }
            }
        },
        "unit_keyword": {
            "_parent": {
                "type": "unit_info" 
            },
            "dynamic": false,
            "properties": {
                "unit_keyword_busi_id":{
                    "type":"keyword"
                },
                "unit_keyword_text":{
                    "type":"text",
                    "fields":{
                        "cn":{
                            "type":"text",
                            "analyzer": "ik_smart"
                        },
                        "en":{
                            "type":"text",
                            "analyzer":"ik_max_word"
                        },
                        "totalword":{
                            "type":"keyword"
                        },
                        "ngram":{
                            "type": "text",
                            "analyzer": "ngram_analyzer"
                        }
                    }
                }
            }
        },
        "unit_output": {
            "_parent": {
                "type": "unit_info" 
            },
            "dynamic": false,
            "properties": {
                "u_out_busi_id":{
                    "type":"keyword"
                },
                "u_out_fruit_name":{
                    "type":"text"
                },
                "u_out_fruit_keyword_arr":{
                    "type":"keyword"
                }
            }
        }
    }
}需求:根据关键词查询机构,并且同时得出这些机构发表的包含有该关键词的专利数,并按照专利数进行倒序排序。
也就是查询条件同时匹配父子表,然后根据字表的数量进行排序
目前我只是实现了查询,查询语句和结果如下:
POST /unit_idx/unit_info/_search
{
    "query": {
        "bool": {
            "must": [
               {
                   "has_child": {
                        "filter": {
                            "term": {
                              "unit_keyword_text.totalword": {
                                "value": "新材料"
                              }
                            }
                        },
                        "type": "unit_keyword"
                    }
               },
               {
                   "has_child": {
                       "query": {
                            "term": {
                              "u_out_fruit_keyword_arr": "新材料"
                            }
                        },
                        "type": "unit_output",
                        "inner_hits":{   
                            "size":0
                        }
                   }
               }
            ]
        }
    }
}问题:
根据查询结果,我想把有15个子元素的机构排在有三个子元素的机构上方,DSL语句中排序那里应该怎么写?

	
2 个回复
zcc_vv - 95
赞同来自:
yixiongmao
赞同来自: