나는이처럼 보이는 중첩 된 문서와 인덱스가 있다고 가정는 집계 elasticsearch에 두 개의 키를 가질 수
{
"mappings": {
"assignment": {
"properties":{
"id": {
"type": "string"
},
"location": {
"type": "string"
},
"typeOfLoss":{
"type": "string"
},
"lineItems": {
"type": "nested",
"properties": {
"categoryCode":{
"type": "string"
},
"selectorCode":{
"type": "string"
},
"roomType": {
"type": "string"
}
}
}
내가 지금 selectorCode를 반환 "lineItems"문서의 카운트 집계를 얻고 싶은와 categoryType 여기서 roomType은 검색 쿼리와 일치합니다. 나는 elasticsearch에 새로운 오전 SQL
SELECT COUNT(*) as theCount, ln.category_code, ln.selector_code
FROM line_items as ln, assignment
WHERE assignment.location = "84043"
AND assignment.typeOfLoss = "Fire"
AND ln.roomType = "kitchen"
GROUP BY ln.category_code, ln.selector_code
ORDER BY theCount DESC;
나는 NEST 쿼리를 시작했지만 몇 가지 문제가 오전에 내 쿼리를 작성할 수있는 사람이 올바른 방향으로 날 지점 수 있습니다 기대하고있다.
var typeOfLossQuery = new TermQuery
{
Field = "typeOfLoss",
Value = typeOfLoss
};
var locationQuery = new TermQuery
{
Field = "location",
Value = location
};
var roomTypeQuery = new TermQuery
{
Field = "roomType",
Value = roomType
};
var result = client.Search<LineItem>(s => s
.From(0)
.Size(numberOfItems)
.Query(q => q.HasParent<Assignment>(a => a
.Query(x =>x
.MatchAll() && typeOfLossQuery && locationQuery
)
) && q.MatchAll() && roomTypeQuery
));
모든 노력에 감사드립니다! 나는이 질문에 당신이 두 개의 열쇠를 가질 수는 없지만 나의 문제는 해결하지 못한다고 대답한다고 생각합니다. C1과 C2의 두 범주 코드가 있고 C1의 내부에 SelectorCode : S1, S1, S2 및 S3이 있으면 C2에서 SelectorCodes : S1, S1, S1을가집니다. CategoryCode 및 SelectorCode 쌍이 가장 많이 발생하기 때문에 C2, S1을 첫 번째 항목으로 가져오고 싶습니다. 그러나 예를 들어 C1, S1, C1, S2, C1, S3를 얻으므로 CategoryCode, SelectorCode . –
나는 네가하는 말을 듣는다. 모든 데이터가 있지만 원하는대로 정렬하려면 약간의 작업이 필요합니다. 당신은 단지 '주문 (1) DESC'만으로는 충분하지 않습니다. – jhilden