私はメールで連絡先を検索する必要があります。 ES documentationによれば、これを達成する最も良い方法はuax_url_email
トークナイザを使用することです。ElasticSearch完全一致のメールを検索
settings: {
index: {
creation_date: "1467895098804",
analysis: {
analyzer: {
email: {
type: "custom",
tokenizer: "uax_url_email"
}
}
},
number_of_shards: "5",
number_of_replicas: "1",
uuid: "wL0P6OIaQqqYpFDvIHArTw",
version: {
created: "2030399"
}
}
}
とマッピング:
contact: {
dynamic: "false",
properties: {
contact_status: {
type: "string"
},
created_at: {
type: "date",
format: "strict_date_optional_time||epoch_millis"
},
email: {
type: "string"
},
id: {
type: "long"
},
mailing_ids: {
type: "long"
},
subscription_status: {
type: "string"
},
type_ids: {
type: "long"
},
updated_at: {
type: "date",
format: "strict_date_optional_time||epoch_millis"
},
user_id: {
type: "long"
}
}
}
インデックスを作成した後、私は二つの文書に挿入しました:ここに私のインデックスの設定である
curl -X PUT 'localhost:9200/contacts/contact/2' -d '{"contact_status": "confirmed", "email": "[email protected]", "id": "2", "user_id": "2", "subscription_status": "on"}'
その後
curl -X PUT 'localhost:9200/contacts/contact/1' -d '{"contact_status": "confirmed", "email": "[email protected]", "id": "1", "user_id": "1", "subscription_status": "on"}'
とをIメールで連絡先を検索しようとしていますさまざまな方法で:
curl -X POST 'localhost:9200/contacts/_search?pretty' -d '{"query": {"bool": {"must": [ {"match": {"_all": { "query": "[email protected]", "analyzer": "email" } } } ] } } }'
私は、ID = 1の1件の結果を得るために期待されるが、空のヒットを得た:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
私がテストした次の検索クエリがあった。
curl -X POST 'localhost:9200/contacts/_search?pretty' -d '{"query": {"bool": {"must": [ {"match": {"_all": { "query": "[email protected]", "analyzer": "email" } } } ] } } }'
2件の結果が返されました:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 0.016878016,
"hits" : [ {
"_index" : "contacts",
"_type" : "contact",
"_id" : "2",
"_score" : 0.016878016,
"_source" : {
"contact_status" : "confirmed",
"email" : "[email protected]",
"id" : "2",
"user_id" : "2",
"subscription_status" : "on"
}
}, {
"_index" : "contacts",
"_type" : "contact",
"_id" : "1",
"_score" : 0.016878016,
"_source" : {
"contact_status" : "confirmed",
"email" : "[email protected]",
"id" : "1",
"user_id" : "1",
"subscription_status" : "on"
}
} ]
}
}
あなたが理解しているように、私は検索結果に1文書を得ることを期待していました。私は間違って何をしていますか?
「email」にメールアドレスのみが含まれている場合、そのフィールドを「not_analyzed」としてから、「term」フィルタを使用してメールアドレスを検索してください。 –
私はuser_id、id、および他のフィールドでも検索する必要があるためです。以上のように、私は電子メールの一部で検索したいと思っています。入力に 'example'と入力し、私の場合は両方の文書で 'example'を含む電子メールのリストを取得します。または、「gmail.com」=> id 1の文書を取得する場合 – Hroft
私はこの方法を提案しています:http://stackoverflow.com/questions/30115867/elasticsearch-analyzer-and-tokenizer-for-emailsそれ以外のユースケースを私に教えてください。 –