如何在Elasticsearch中使用折叠编写查询以进行组排序?

时间:2019-05-31 10:57:24

标签: elasticsearch

无法在以下查询中对inner_hits.sub_places.hits.total.value进行排序,如果可以的话,请与我们分享您的答案,这将对我们有帮助。

请检查下面添加的查询和结果,以防万一,如果您在此处发现错误也可以纠正我们。

此外,我们还可以提供其他记录此功能的查询

{   
  "from": 0,
  "size" : 1000,
    "query":{
    "bool":{
        "must":[{
          "multi_match":{
            "query":"A",
            "fields":["place_name","properties.top_category","properties.brands"]
          }
        }]
      }
    },
  "_source" : ["place_name", "properties.top_category" , "properties.sub_category", "properties.naics_code"],
  "collapse" : {
      "field" : "place_name.keyword",
      "inner_hits": {
        "name": "sub_places",
        "ignore_unmapped": false,
        "from": 0,
        "size": 2,
        "version": false,
        "explain": false,
        "track_scores": false
        }
      }
}

这是我使用上述查询时的结果。

{      
  "hits": [
            {
                "_index": "places-integration",
                "_type": "_doc",
                "_id": "dvYK3moBpY3ocjU7pDLg",
                "_score": 4.3429465,
                "_source": {
                    "place_name": "&&&&&&&",
                    "properties": {
                        "naics_code": "812113",
                        "sub_category": "%%%%%%",
                        "top_category": "%%%%%%"
                    }
                },
                "fields": {
                    "place_name.keyword": [
                        "A Nail"
                    ]
                },
                "inner_hits": {
                    "sub_places": {
                        "hits": {
                            "total": {
                                "value": 3,
                                "relation": "eq"
                            },
                            "max_score": null,
                            "hits": []
                        }
                    }
                }
            },
            {
                "_index": "places-integration",
                "_type": "_doc",
                "_id": "kvYK3moBpY3ocjU7pDDe",
                "_score": 3.762603,
                "_source": {
                    "place_name": "$$$$$$$",
                    "properties": {
                        "naics_code": "33333",
                        "sub_category": "#######",
                        "top_category": "#######"
                    }
                },
                "fields": {
                    "place_name.keyword": [
                        "A Belltower Cathedral"
                    ]
                },
                "inner_hits": {
                    "sub_places": {
                        "hits": {
                            "total": {
                                "value": 5,
                                "relation": "eq"
                            },
                            "max_score": null,
                            "hits": []
                        }
                    }
                }
            }
}

0 个答案:

没有答案