ElasticSearch-고유 값 반환
languages
레코드에서 모든 값을 가져 와서 고유하게 만드는 방법은 무엇입니까 ?
기록
PUT items/1
{ "language" : 10 }
PUT items/2
{ "language" : 11 }
PUT items/3
{ "language" : 10 }
질문
GET items/_search
{ ... }
# => Expected Response
[10, 11]
어떤 도움이라도 좋을 것입니다.
집계라는 용어 를 사용할 수 있습니다 .
{
"size": 0,
"aggs" : {
"langs" : {
"terms" : { "field" : "language", "size" : 500 }
}
}}
검색하면 다음과 같은 결과가 반환됩니다.
{
"took" : 16,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"hits" : {
"total" : 1000000,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"langs" : {
"buckets" : [ {
"key" : "10",
"doc_count" : 244812
}, {
"key" : "11",
"doc_count" : 136794
}, {
"key" : "12",
"doc_count" : 32312
} ]
}
}
}
size
집계 지정 내의 파라미터 용어의 최대 수는 집계 결과에 포함한다. 모든 결과가 필요한 경우 데이터의 고유 용어 수보다 큰 값으로 설정하십시오.
Elasticsearch 1.1+에는 고유 한 개수를 제공 하는 카디널리티 집계 가 있습니다.
실제로는 근사치이며 높은 카디널리티 데이터 세트로 정확도가 떨어질 수 있지만 일반적으로 테스트에서는 꽤 정확합니다.
You can also tune the accuracy with the precision_threshold
parameter. The trade-off, or course, is memory usage.
This graph from the docs shows how a higher precision_threshold
leads to much more accurate results.
I am looking for this kind of solution for my self as well. I found reference in terms aggregation.
So, according to that following is the proper solution.
{
"aggs" : {
"langs" : {
"terms" : { "field" : "language",
"size" : 500 }
}
}}
But if you ran into following error:
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [fastest_method] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
]}
In that case, you have to add "KEYWORD" in the request, like following:
{
"aggs" : {
"langs" : {
"terms" : { "field" : "language.keyword",
"size" : 500 }
}
}}
참고URL : https://stackoverflow.com/questions/25465215/elasticsearch-return-unique-values
'program story' 카테고리의 다른 글
내부 오류 500 Apache이지만 로그에 아무것도 없습니까? (0) | 2020.08.12 |
---|---|
디버깅을위한 의미있는 출력을 제공하기 위해 JavaScript의 toString () 함수를 재정의 할 수 있습니까? (0) | 2020.08.12 |
마스터 브랜치로 변경할 때 오류 : 체크 아웃시 로컬 변경 사항을 덮어 씁니다. (0) | 2020.08.11 |
C #이 기본적으로 비가 상 메서드를 구현하는 이유는 무엇입니까? (0) | 2020.08.11 |
N 채널을 듣는 방법? (0) | 2020.08.11 |