Elasticsearch 学习之Field Collapsing(字段折叠)

Field Collapsing(字段折叠)不能与scroll、rescore以及search after 结合使用

  • collapse字段:表示按照age(每个age对应多条document结果)的值折叠(keyword或者数值)
  • sort:表示按照age字段排序
  • from:偏移,即前180个document的值都被折叠掉了

    curl -XGET "http://localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
    {
        "query": {
    "match": {
        "address": "Place"
    }
     },
        "collapse" : {
            "field" : "age" 
     },
        "sort": ["age"], 
        "from": 10
            }''
    
  • Expand collapse results(对于每个折叠的结果,可以通过inner_hits展开结果)

    • max_concurrent_group_searches:允许每组检索inner_hits的并发请求数 (默认按照线程池的大小或者数据节点数)
    • 单个inner_hits

      curl -XGET "http://localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
      {
      "query": {
          "match": {
              "address": "Place"
          }
      },
      "collapse" : {
          "field" : "age", 
          "inner_hits": {
              "name": "test", 
              "size": 5, 
              "sort": [{ "age": "asc" }] 
          },
          "max_concurrent_group_searches": 4 
      },
      "sort": ["age"]
      }'
      
    • 多个inner_hits

      curl -XGET "http://localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
      {
          "query": {
              "match": {
                  "address": "Place"
              }
          },
          "collapse" : {
              "field" : "age", 
              "inner_hits":[ {
                  "name": "age", 
                  "size": 2, 
                  "sort": [{ "age": "asc" }] 
              },
              {
              "name":"account_number",
              "size": 2, 
              "sort": [{ "account_number": "asc" }] 
              }],
              "max_concurrent_group_searches": 4
          },
          "sort": ["age"]
      }'
      

猜你喜欢

转载自blog.csdn.net/yiyiholic/article/details/81634435