Is there a way to do exact and full-text searching without creating two different fields?

Is there a way to do exact and full text searches without having to create
two different fields?

The documentation
(http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_finding_exact_values.html)
states fields must have the mapping "not_analyzed" in order to avoid
tokenization. This allows exact searches to be done.

In my case, I would like both full text search and exact searches. For
example:

When searching for book titles, a user can input either:

I like ElasticSearch

-OR-

exact="I like ElasticSearch"

The first case will return results from a full text search.

The second case will return results only if the book title is exactly "I
like ElasticSearch". Case sensitivity does not matter.

To do this, I think I will have to create two fields called "book_title"
and "book_title_exact" where "book_title_exact" will have a field mapping
"not_analyzed" so that I can do exact matches.

Is this the proper way of handling my use case? Or is there a simpler way
in ES without having to store a title twice?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ac298481-b0f0-4052-a115-388e9db92f50%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Look at multifields. They let you send the field once and analyze it
multiple times. You also might want to use keyword ananlyzer and lowercase
filter rather than not_analyzed. Folks are used to case insensitivity.

Nik
Is there a way to do exact and full text searches without having to create
two different fields?

The documentation (
http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_finding_exact_values.html)
states fields must have the mapping "not_analyzed" in order to avoid
tokenization. This allows exact searches to be done.

In my case, I would like both full text search and exact searches. For
example:

When searching for book titles, a user can input either:

I like ElasticSearch

-OR-

exact="I like ElasticSearch"

The first case will return results from a full text search.

The second case will return results only if the book title is exactly "I
like ElasticSearch". Case sensitivity does not matter.

To do this, I think I will have to create two fields called "book_title"
and "book_title_exact" where "book_title_exact" will have a field mapping
"not_analyzed" so that I can do exact matches.

Is this the proper way of handling my use case? Or is there a simpler way
in ES without having to store a title twice?

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/ac298481-b0f0-4052-a115-388e9db92f50%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/ac298481-b0f0-4052-a115-388e9db92f50%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAPmjWd3tzungzKTtCrxeLJrLpFJEdiGokqP7%2BuQS5ZB388-mTQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ah, thanks. I've set this up (using ES python bindings):

es.indices.put_mapping(index="myindex",
doc_type="books",
body={
"books": {
"properties": {
"title": {
"type": "string",
"fields": {
"name": { "type"
: "string" },
"raw": { "type":
"string", "index": "not_analyzed" }
} } } } } )

Then I try to search for exact match:

es.search(index='myindex', doc_type="books", body={"query": { "filtered": {
"filter": { "term": { "title": { "raw" : "I like Elasticsearch" } } } } } }
)

But I get an ES error stating

nested: QueryParsingException[[myindex] [term] filter does not support
[raw]]; }]')

It seems like I'm not searching for the raw correctly. How would I specify
to search for the raw title (exact matching)?

On Sunday, December 14, 2014 6:49:09 PM UTC-5, Nikolas Everett wrote:

Look at multifields. They let you send the field once and analyze it
multiple times. You also might want to use keyword ananlyzer and lowercase
filter rather than not_analyzed. Folks are used to case insensitivity.

Nik
Is there a way to do exact and full text searches without having to create
two different fields?

The documentation (
Elasticsearch Platform — Find real-time answers at scale | Elastic)
states fields must have the mapping "not_analyzed" in order to avoid
tokenization. This allows exact searches to be done.

In my case, I would like both full text search and exact searches. For
example:

When searching for book titles, a user can input either:

I like Elasticsearch

-OR-

exact="I like Elasticsearch"

The first case will return results from a full text search.

The second case will return results only if the book title is exactly "I
like Elasticsearch". Case sensitivity does not matter.

To do this, I think I will have to create two fields called "book_title"
and "book_title_exact" where "book_title_exact" will have a field mapping
"not_analyzed" so that I can do exact matches.

Is this the proper way of handling my use case? Or is there a simpler way
in ES without having to store a title twice?

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/ac298481-b0f0-4052-a115-388e9db92f50%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/ac298481-b0f0-4052-a115-388e9db92f50%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/413133ef-c82e-4bff-9a9f-af9bd9f56815%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I think I just figured it out:

{"title.raw" : "I like Elasticsearch"}

instead of

"title: { "raw": "I like Elasticsearch" }

On Sunday, December 14, 2014 9:00:52 PM UTC-5, am wrote:

Ah, thanks. I've set this up (using ES python bindings):

es.indices.put_mapping(index="myindex",
doc_type="books",
body={
"books": {
"properties": {
"title": {
"type": "string",
"fields": {
"name": {
"type": "string" },
"raw": {
"type": "string", "index": "not_analyzed" }
} } } } } )

Then I try to search for exact match:

es.search(index='myindex', doc_type="books", body={"query": { "filtered":
{ "filter": { "term": { "title": { "raw" : "I like Elasticsearch" } } } }
} } )

But I get an ES error stating

nested: QueryParsingException[[myindex] [term] filter does not support
[raw]]; }]')

It seems like I'm not searching for the raw correctly. How would I specify
to search for the raw title (exact matching)?

On Sunday, December 14, 2014 6:49:09 PM UTC-5, Nikolas Everett wrote:

Look at multifields. They let you send the field once and analyze it
multiple times. You also might want to use keyword ananlyzer and lowercase
filter rather than not_analyzed. Folks are used to case insensitivity.

Nik
Is there a way to do exact and full text searches without having to
create two different fields?

The documentation (
Elasticsearch Platform — Find real-time answers at scale | Elastic)
states fields must have the mapping "not_analyzed" in order to avoid
tokenization. This allows exact searches to be done.

In my case, I would like both full text search and exact searches. For
example:

When searching for book titles, a user can input either:

I like Elasticsearch

-OR-

exact="I like Elasticsearch"

The first case will return results from a full text search.

The second case will return results only if the book title is exactly "I
like Elasticsearch". Case sensitivity does not matter.

To do this, I think I will have to create two fields called "book_title"
and "book_title_exact" where "book_title_exact" will have a field mapping
"not_analyzed" so that I can do exact matches.

Is this the proper way of handling my use case? Or is there a simpler way
in ES without having to store a title twice?

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/ac298481-b0f0-4052-a115-388e9db92f50%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/ac298481-b0f0-4052-a115-388e9db92f50%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/f5ad817d-f36c-495f-99cc-8dbe96e78e3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.