Gracjan Polak
Gracjan Polak

Reputation: 596

ElasticSearch analyzed and not_analyzed at the same time

My documents for ElasticSearch are of the form:

{
    "message": "Message text",
    "user_email": "user@email.net"
}

There are two types of queries executed against these documents:

  1. Human queries over '_all' fields that should match both 'message' and 'user_email' using analyzers.
  2. Machine queries that should use exact match 'user_email'.

Is there a way to create both 'analyzed' and 'not_analyzed' indexes for a single field in ElasticSearch?

Upvotes: 1

Views: 277

Answers (1)

Zouzias
Zouzias

Reputation: 2360

A simple solution to the above problem is to define two different fields corresponding to user_email, i.e., "user_email_analyzed" and "user_email_not_analyzed" when creating the index. Afterwards, during the indexing phase, you should update the context on both email fields.

Upvotes: 1

Related Questions