elasticsearch 조회 집합 결과 정렬

4258 단어 elasticsearch
1. 조회 결과는 어떤 필드에 따라 정렬된다
{
  "size" : 5,
  "query" : {
    "bool" : {
      "filter" : [
        {
          "range" : {
            "startTime" : {
              "from" : 1517046960000,
              "to" : 1517048760000
            }
          }
        }
      ]
    }
  },
  "sort" : [{ "startTime" : { "order" : "desc"}}
  ]
}
//javaApi size orderstr 
SearchRequestBuilder srb = this.createSearchRequestBuilder(new Date(begin), new Date(end));
srb.setQuery(queryBuilder).setSize(queryParam.getPageIndex() * queryParam.getPageSize())
									.addSort(orderStr, SortOrder.ASC);

2. 집합 결과 정렬
1. 조회된 문서 수에 따라
 :"order" : {  "_count" : "desc" }
{"size": 0, 
  "query" : {
    "bool" : {
      "filter" : [
        { "range" : {
            "startTime" : {
              "from" : 1515655800000,
              "to" : 1516865400000
            }
          } },
        { "term" : {
            "type" : {
              "value" : "URL",
              "boost" : 1.0
            }
          } }
      ]
    }
  },
  "aggregations" : {
    "CATEGORY" : {
      "terms" : {
        "field" : "errorCode",
        "size" : 5,
        "order" : {
          "_count" : "desc"
        }
      }
    }
  }
}
// java “_count”  
TermsAggregationBuilder termsAggBuilder=AggregationBuilders.terms(AggAlias.CATEGORY.getValue()).field(cateGoryFieldName);
termsAggBuilder.order(Terms.Order.count(false)).size(5);
		

(2), 하위 집합 결과에 따라 정렬
       
{
  "query" : {
    "bool" : {
      "filter" : [
        {
          "term" : {
            "type" : {
              "value" : "URL",
              "boost" : 1.0
            }
          }
        }
      ]
    }
  },
  "aggregations" : {
    "CATEGORY" : {
      "terms" : {
        "field" : "name",
        "size" : 5,
        "order" : {"responseTime.avg" : "asc" }
      },
      "aggregations" : {
        "responseTime" : {
          "extended_stats" : {
            "field" : "durationInMillis",
            "sigma" : 2.0
          }
        },
        "error" : {
          "sum" : {
            "script" : {
              "inline" : "def errorTemp=doc['status'].value; if(errorTemp=='0'){return 0;}else{return 1;}",
              "lang" : "painless"
            }
          }
        },
        "apdex" : {
          "avg" : {
            "script" : {
              "inline" : "def responseTemp=doc['durationInMillis'].value; if(responseTemp>params.threshold){return 0.5;}else{return 1;}",
              "lang" : "painless",
              "params" : {
                "threshold" : 20.0
              }
            }
          }
        },
        "errorRate" : {
          "percentile_ranks" : {
            "script" : {
              "inline" : "def errorTemp=doc['status'].value; if(errorTemp=='0'){return 1;}else{return 0;}",
              "lang" : "painless"
            },
            "values" : [
              0.0
            ],
            "keyed" : true,
            "tdigest" : {
              "compression" : 100.0
            }
          }
        }
      }
    }
  }
}
   
     
//   orderStr===responseTime.avg   ascOrder=true  
AggregationBuilders.terms(AggAlias.CATEGORY.getValue()).field(categoryfieldName).order(Terms.Order.aggregation(orderStr,ascOrder)).size(size)
여러분, 다른 정렬 방식이 있다면 함께 토론하는 것을 환영합니다.

좋은 웹페이지 즐겨찾기