2016-10-03 18 views
0

が、私はこのクエリを使用しているとして扱う単一のフィールドである(SQLfyingはSELECT field, count(field) GROUP BY fieldだろうElasticSearch集約は:スペースを含む文字列値を取得するために、2つの文字列

私はそれを行うために。 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"のための別の1:
{ 
    "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は私に2つの値を取得しています。ショール値"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.*フィールドに設定できますか。

EDIT

私がテストしてみた:

#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

関連する問題