2016-04-07 19 views
0

上のアナライザはこんにちは私はpostfixのために、このテンプレートを使用しています:Elasticsearch:ネストされた要素

PUT /_template/postfix 
{ 
    "template": "postfix*", 
    "settings":{ 
    "index":{ 
     "analysis":{ 
      "analyzer":{ 
       "email":{ 
       "tokenizer":"keyword", 
       "filter":"lowercase" 
       } 
      } 
     } 
    } 
    }, 
    "mappings": { 
    "logs": { 
     "properties": { 
     "@timestamp": { 
      "type": "date", 
      "format": "strict_date_optional_time||epoch_millis" 
     }, 
     "@version": { 
      "type": "string" 
     }, 
     "clienthostname": { 
      "type": "string" 
     }, 
     "clientip": { 
      "type": "ip" 
     }, 
     "delay": { 
      "type": "double" 
     }, 
     "deferred": { 
      "type": "boolean" 
     }, 
     "delays": { 
      "type": "string" 
     }, 
     "dsn": { 
      "type": "string" 
     }, 
     "entry_date": { 
      "type": "string" 
     }, 
     "lastqueueid": { 
      "type": "string" 
     }, 
     "logsource": { 
      "type": "string" 
     }, 
     "mailfrom": { 
      "type": "string", 
      "index": "not_analyzed" 
     }, 
     "mailsize": { 
      "type": "long" 
     }, 
     "numberofrecipients": { 
      "type": "long" 
     }, 
     "pid": { 
      "type": "long" 
     }, 
     "postfixdaemon": { 
      "type": "string" 
     }, 
     "program": { 
      "type": "string" 
     }, 
     "queueid": { 
      "type": "string" 
     }, 
     "recipients": { 
      "type" : "nested", 
      "properties": { 
      "rcptto": {"type": "string", "analyzer":"email" } 
      } 
     }, 
     "relay": { 
      "type": "string" 
     }, 
     "relayip": { 
      "type": "string" 
     }, 
     "removal_time": { 
      "type": "string" 
     }, 
     "removed": { 
      "type": "string" 
     }, 
     "status": { 
      "type": "string" 
     }, 
     "tags": { 
      "type": "string" 
     }, 
     "timestamp": { 
      "type": "string" 
     }, 
     "total_delay": { 
      "type": "long" 
     } 
     } 
    } 
    } 
} 

私の受信者フィールドがネストされている、と私は(仕事をする完全なメールアドレスを保持し、に変換するアナライザを使用しています小文字)。

GET /_analyze 
{ 
    "tokenizer":"uax_url_email", 
    "filters":["lowercase"], 
    "text":["test","[email protected]"] 

} 

それは返します:私はそれがうまく仕事をしています。この要求にアナライザをテストしていた場合

{ 
    "tokens": [ 
     { 
     "token": "test", 
     "start_offset": 0, 
     "end_offset": 4, 
     "type": "<ALPHANUM>", 
     "position": 0 
     }, 
     { 
     "token": "[email protected]", 
     "start_offset": 5, 
     "end_offset": 27, 
     "type": "<EMAIL>", 
     "position": 1 
     } 
    ] 
} 

をしかし、私は私のデータをインデックス化していたときに、recipients.rcptoフィールドが小文字に変換されていません、受信者の検索要求を行うと、それはうまくいきません。 rcpttoパートのインデックスが正しくないようです。

インデックスデータ: "ステータス" フィールドに基づいて

POST /postfix/logs 
{ 
       "status" : "sent", 
       "queueid" : "3nTgBP6Mrpz18dwD", 
      "postfixdaemon" : "smtpd", 
      "recipients" : [ 
      { 
       "rcptto" : "[email protected]" 
      }, 
      { 
       "rcptto" : "[email protected]" 
      } 
     ], 
       "mailfrom" : "[email protected]", 
       "clientip" : "127.0.0.1", 
     "clienthostname" : "server.fr", 
        "pid" : 7996, 
       "delays" : "0.06/0/0/0.28", 
       "logsource" : "smtp2", 
      "total_delay" : 1, 
       "mailsize" : 23792, 
        "delay" : 0.34, 
       "program" : "postfix", 
      "entry_date" : "Jan 5 00:45:33", 
       "timestamp" : "Jan 5 00:45:33", 
       "removed" : "True", 
       "@version" : "1", 
      "@timestamp" : "2016-01-04T23:45:33.000Z" 
} 

要求:

GET /postfix*/_search 
{ 
    "fields":"recipients.rcptto", 
    "query": { 
    "term": { 
     "status": "sent" 
    } 
    } 
} 

戻る:

{ 
    "took": 2, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 1, 
     "max_score": 0.30685282, 
     "hits": [ 
     { 
      "_index": "postfix", 
      "_type": "logs", 
      "_id": "AVP00rA5U5V4nhi9E0IJ", 
      "_score": 0.30685282, 
      "fields": { 
       "recipients.rcptto": [ 
        "[email protected]", 
        "[email protected]" 
       ] 
      } 
     } 
     ] 
    } 
} 

"recipients.rcptto" フィールドに基づいて要求(と更新リチャの返信):

{ 
"query": { 
    "nested": { 
    "path": "recipients", 
    "query": { 
     "match": { 
      "recipients.rcptto": "[email protected]" 
      } 
     } 
    } 
    } 
} 

リターン:受信者が小文字に変換されません

{ 
    "took": 6, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 1, 
     "max_score": 1.4054651, 
     "hits": [ 
     { 
      "_index": "postfix", 
      "_type": "logs", 
      "_id": "AVP1zqtwU5V4nhi9E0Ih", 
      "_score": 1.4054651, 
      "_source": { 
       "status": "sent", 
       "queueid": "3nTgBP6Mrpz18dwD", 
       "postfixdaemon": "smtpd", 
       "recipients": [ 
        { 
        "rcptto": "[email protected]" 
        }, 
        { 
        "rcptto": "[email protected]" 
        } 
       ], 
       "mailfrom": "[email protected]", 
       "clientip": "127.0.0.1", 
       "clienthostname": "server.fr", 
       "pid": 7996, 
       "delays": "0.06/0/0/0.28", 
       "logsource": "smtp2", 
       "total_delay": 1, 
       "mailsize": 23792, 
       "delay": 0.34, 
       "program": "postfix", 
       "entry_date": "Jan 5 00:45:33", 
       "timestamp": "Jan 5 00:45:33", 
       "removed": "True", 
       "@version": "1", 
       "@timestamp": "2016-01-04T23:45:33.000Z" 
      } 
     } 
     ] 
    } 
} 

、それは正常ですか?

+0

は、なぜあなたは、あなたのフィールドが小文字に変換取得されていないことを感じていますか?どのクエリを実行していますか? – Richa

+0

こんにちは、あなたのフィードバックのおかげで私は私の記事を編集しました。 – neb0

答えて

0

元のデータとインデックスデータを区別する必要があります。

あなたのインデックスメール[email protected]もしあなたがソースフィールドとあなたのインデックスに[email protected][email protected]を持つことになります。あなたのフィールドがnestedあなたですので

+0

返信いただきありがとうございますが、これは問題ではありません。私は詳細を提供するためにイニシャルを更新しました。 – neb0

+0

Elasticsearchは、テキストの大文字と小文字を変更せずに元の形式でソースデータを保持します。小文字の変換はインデックス内でのみ発生します。このインデックスで検索すると、元のデータが返されます。これは予想される動作です。 – pkhlop

1

を使用すると、ESで電子メールを検索する場合、それはインデックスであるため、

それは、あなたが[email protected]につながる返しますが、ないため[email protected]Match Queryの組み合わせでNested Queryを使用する必要があります。 Term Queryを使用しないでください。正確に一致するものが検索されます。

{ 
"query": { 
    "nested": { 
    "path": "recipients", 
    "query": { 
     "match": { 
      "recipients.rcptto": "[email protected]" 
      } 
     } 
    } 
    } 
} 

はそれが役に立てば幸い

...

+0

@ neb0あなたのために働いていますか???? – Richa

関連する問題