2016-10-03 3 views
0

내가이 쿼리를 사용하고 있습니다로 처리 하나의 필드에있다 (SQLfying는 SELECT field, count(field) GROUP BY fieldElasticSearch 집계 : 공백 문자열 값 얻기 위해서 두 개의 문자열

난 그렇게하기 위해서. ES이 요청을 전송 :이 컬렉션에 하나 개의 문서가있다

{ 
    "query" : { 
    "bool" : { 
     "must" : { 
     "exists" : { 
      "field" : "metainfos.ceeaacceaeaaccebeaacceceaaccedeaac" 
     } 
     } 
    } 
    }, 
    "aggregations" : { 
    "followUpActivity.metainfo.metainfos.ceeaacceaeaaccebeaacceceaaccedeaac" : { 
     "terms" : { 
     "field" : "metainfos.ceeaacceaeaaccebeaacceceaaccedeaac", 
     "missing" : "null" 
     } 
    } 
    } 
} 

:

{ 
    "took" : 1, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 1, 
    "successful" : 1, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 1, 
    "max_score" : 1.0, 
    "hits" : [ { 
     "_index" : "living_v1", 
     "_type" : "fuas", 
     "_id" : "a2cb0ba1-8955-11e6-8a00-0242ac110007", 
     "_score" : 1.0, 
     "_routing" : "user2", 
     "_source" : { 
     "user" : "user2", 
     "timestamp" : "2016-10-03T11:08:30.074Z", 
     "startTimestamp" : "2016-10-03T11:08:30.074Z", 
     "dueTimestamp" : null, 
     "closingTimestamp" : null, 
     "matter" : "Fua 1", 
     "comment" : null, 
     "status" : 0, 
     "backlogStatus" : 20, 
     "metainfos" : { 
      "ceeaacceaeaaccebeaacceceaaccedeaac" : [ "Living Digital" ] 
     }, 
     "resources" : [ ], 
     "notes" : null 
     } 
    } ] 
    } 
} 

으로 당신이 볼 수 doc.metainfos.ceeaacc... = ["Living Digital"]

에 대한 하나 "digital" 또 다른 하나
{ 
    "took" : 3, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 1, 
    "successful" : 1, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 1, 
    "max_score" : 1.0, 
    "hits" : [ { 
     "_index" : "living_v1", 
     "_type" : "fuas", 
     "_id" : "a2cb0ba1-8955-11e6-8a00-0242ac110007", 
     "_score" : 1.0, 
     "_routing" : "user2", 
     "_source":{"user":"user2","timestamp":"2016-10-03T11:08:30.074Z","startTimestamp":"2016-10-03T11:08:30.074Z","dueTimestamp":null,"closingTimestamp":null,"matter":"Fua 1","comment":null,"status":0,"backlogStatus":20,"metainfos":{"ceeaacceaeaaccebeaacceceaaccedeaac":["Living Digital"]},"resources":[],"notes":null} 
    } ] 
    }, 
    "aggregations" : { 
    "followUpActivity.metainfo.metainfos.ceeaacceaeaaccebeaacceceaaccedeaac" : { 
     "doc_count_error_upper_bound" : 0, 
     "sum_other_doc_count" : 0, 
     "buckets" : [ { 
     "key" : "digital", 
     "doc_count" : 1 
     }, { 
     "key" : "living", 
     "doc_count" : 1 
     } ] 
    } 
    } 
} 

ES는 나에게 두 값을 받고있다. 나는 shole 값 "Living Digital"을 사용하여 집합을 얻고 싶습니다.

매핑 방식은 다음과 같습니다

{ 
    "living_v1" : { 
    "mappings" : { 
     "fuas" : { 
     "properties" : { 
      "backlogStatus" : { 
      "type" : "long" 
      }, 
      "comment" : { 
      "type" : "string" 
      }, 
      "matter" : { 
      "type" : "string" 
      }, 
      "metainfos" : { 
      "properties" : { 
       "ceeaacceaeaaccebeaacceceaaccedeaac" : { 
       "type" : "string" 
       } 
      } 
      }, 
      "startTimestamp" : { 
      "type" : "date", 
      "format" : "strict_date_optional_time||epoch_millis" 
      }, 
      "status" : { 
      "type" : "long" 
      }, 
      "timestamp" : { 
      "type" : "date", 
      "format" : "strict_date_optional_time||epoch_millis" 
      }, 
      "user" : { 
      "type" : "string", 
      "index" : "not_analyzed" 
      } 
     } 
     } 
    } 
    } 
} 

당신이 볼 수 있듯이 :

"metainfos" : { 
    "properties" : { 
     "ceeaacceaeaaccebeaacceceaaccedeaac" : { 
      "type" : "string" 
     } 
    } 
} 

나에게 문제는 "ceeaacceaeaaccebeaacceceaaccedeaac는"사용자가 주문형 재산 작성 나도 몰라입니다 어떻게 not-analyzedmetainfos.* 필드로 설정할 수 있습니까?

#curl -XPUT 'http://localhost:9200/living_v1/' -d ' 
{ 
    "mappings": { 
    "fuas": { 
     "dynamic_templates": [ 
     { 
      "metainfos": { 
      "path_match": "metainfos.*", 
      "match_mapping_type": "string", 
      "mapping": { 
       "type": "string", 
       "index": "not_analyzed" 
      } 
      } 
     } 
     ] 
    } 
    } 
} 
' 

living_v1 인덱스가 이미 존재 내게 말하고 :

편집

나는 테스트했습니다. 지금까지 내가 here에 알아낼 수있었습니다 나는 PUTindex에 보낼 필요가 : 이미 눈치로, 검색 동작은 기본적으로 적용된 매핑에 의해 발생

{ 
    "error":{ 
    "root_cause":[ 
     { 
      "type":"index_already_exists_exception", 
      "reason":"already exists", 
      "index":"living_v1" 
     } 
    ], 
    "type":"index_already_exists_exception", 
    "reason":"already exists", 
    "index":"living_v1" 
}, 
"status":400 
} 
+0

동적 색인 템플릿을 찾고 있다고 생각합니다. http://stackoverflow.com/a/23370138/693546 – mblaettermann

답변

1

. 이 매핑은 다르게 정의되지 않은 모든 문자열 값 필드를 분석합니다. 이 필드 그래서 우선 적용되어야하는 매핑 정의 herehere을 설명

그래서 당신은 아직 metainfos 객체에있을 것입니다 수있는 속성 (= 키) 모르는 경우, 당신은 동적 템플릿 기능을 사용할 수 있습니다 문자열 필드를 분석하는 기본 동작 다른 사람들이 지적했듯이

{ 
    "mappings": { 
    "fuas": { 
     "dynamic_templates": [ 
     { 
      "metainfos": { 
      "path_match": "metainfos.*", 
      "match_mapping_type": "string", 
      "mapping": { 
       "type": "string", 
       "index": "not_analyzed", 
      } 
      } 
     } 
     ] 
    } 
    } 
} 
+0

감사합니다. @Andreas . 나는 그것을 시도했지만, 몇 가지 문제가 발생했습니다. 템플릿과 접근 방식의 차이점은 무엇입니까? 그들은 같은가요? – Jordi

1

, 동적 템플릿을 이동하는 방법은 다음과 같습니다

당신은 (하지 테스트)이 같은 비트를 보이는 매핑을 적용 할 수 있습니다. 유일한 문제점은 일부 문서가 색인 된 후에 색인 템플리트를 변경할 수 없다는 것입니다. 색인을 다시 생성해야합니다 (색인 삭제, 매핑 작성, 새 문서 공급)

+0

좋아, @oldbam, 알았다. 'index_v1'에서'index_v2'까지 인덱스를 재현하는 간단한 방법이 있습니까? – Jordi

+1

http://stackoverflow.com/questions/28626803/how-to-rename-an-index-in-a-cluster에서 답을 찾아보십시오. 나는 항상 인덱스를 삭제하고 인덱스 템플릿을 변경할 때 문서를 다시 공급하기 시작했습니다. – oldbam