Really simple text searching


(MarcusLongmuir) #1

I've been using ElasticSearch for a while, but I haven't really dug
into the text search side of things. I went to implement really simple
text searching earlier today and got a bit confused.

From what I understand I can't do a "Whole text value is equal to
search parameter" query because the text was analysed when it was
indexed and doesn't exist in it's whole form? If someone could explain
how to get the following working I'd be very grateful:

Index a piece of text:
"Lorem ipsum dolor sit amet"

And be able to retrieve the document with the following queries:
Phrase: "ipsum dolor"
Contains: "sit"
EqualTo: "Lorem ipsum dolor sit amet"

But not retrieve the document for the following queries:
Phrase: "dolor ipsum"
EqualTo: "dolor sit"

I don't really want users to be able to use keywords in the strings
for the sake of unwanted confusion so keywords like "and" and "or"
should either be ignored or actually searched for rather than being
operators.

Thanks for any advice


(Shay Banon) #2

Hey,

You can use the text query (which analyzes the text you search on) for
simple text matches:
http://www.elasticsearch.org/guide/reference/query-dsl/text-query.html.

Doing an "equal to" on an analyzed fields that gets broken down into
multiple terms is not really possible, but doing phrase searches, or sloppy
phrase searches are certainly possible.

For exact matching, you could have a multi field mapping, with a non
analyzed option on the field, and search against that.

-shay.banon

On Wed, Sep 21, 2011 at 12:22 AM, marcuslongmuir marcuslongmuir@me.comwrote:

I've been using ElasticSearch for a while, but I haven't really dug
into the text search side of things. I went to implement really simple
text searching earlier today and got a bit confused.

From what I understand I can't do a "Whole text value is equal to
search parameter" query because the text was analysed when it was
indexed and doesn't exist in it's whole form? If someone could explain
how to get the following working I'd be very grateful:

Index a piece of text:
"Lorem ipsum dolor sit amet"

And be able to retrieve the document with the following queries:
Phrase: "ipsum dolor"
Contains: "sit"
EqualTo: "Lorem ipsum dolor sit amet"

But not retrieve the document for the following queries:
Phrase: "dolor ipsum"
EqualTo: "dolor sit"

I don't really want users to be able to use keywords in the strings
for the sake of unwanted confusion so keywords like "and" and "or"
should either be ignored or actually searched for rather than being
operators.

Thanks for any advice


(MarcusLongmuir) #3

I appreciate the time you've taken to answer Shay. ElasticSearch is
great.

I'm using the Java API.

How would I go about producing multiple mappings for a single field?
or do you mean having two fields with only one being analysed? And how
do I go about choosing which mapping to use when querying/filtering?

You say "doing phrase searches, or sloppy phrase searches are
certainly possible." Which of my examples do these relate to and how
would I go about implementing this?

I may have misunderstood, but if phrase searches are possible (and by
this I mean "ipsum dolor" is matched, but "dolour ipsum" is not in the
above example), then why is a full "equal to" not possible on the same
analysed field?

Thanks

On Sep 21, 12:19 am, Shay Banon kim...@gmail.com wrote:

Hey,

You can use the text query (which analyzes the text you search on) for
simple text matches:http://www.elasticsearch.org/guide/reference/query-dsl/text-query.html.

Doing an "equal to" on an analyzed fields that gets broken down into
multiple terms is not really possible, but doing phrase searches, or sloppy
phrase searches are certainly possible.

For exact matching, you could have a multi field mapping, with a non
analyzed option on the field, and search against that.

-shay.banon

On Wed, Sep 21, 2011 at 12:22 AM, marcuslongmuir marcuslongm...@me.comwrote:

I've been using ElasticSearch for a while, but I haven't really dug
into the text search side of things. I went to implement really simple
text searching earlier today and got a bit confused.

From what I understand I can't do a "Whole text value is equal to
search parameter" query because the text was analysed when it was
indexed and doesn't exist in it's whole form? If someone could explain
how to get the following working I'd be very grateful:

Index a piece of text:
"Lorem ipsum dolor sit amet"

And be able to retrieve the document with the following queries:
Phrase: "ipsum dolor"
Contains: "sit"
EqualTo: "Lorem ipsum dolor sit amet"

But not retrieve the document for the following queries:
Phrase: "dolor ipsum"
EqualTo: "dolor sit"

I don't really want users to be able to use keywords in the strings
for the sake of unwanted confusion so keywords like "and" and "or"
should either be ignored or actually searched for rather than being
operators.

Thanks for any advice


(Jan Fiedler) #4

Find documentation on multi-field mappings (that Shay mentioned) here:
http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html


(Shay Banon) #5

You can do multiple mapping for a field using the multi_field mapping type:
http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html.

Not sure I understand the other questions.

On Wed, Sep 21, 2011 at 8:18 PM, marcuslongmuir marcuslongmuir@me.comwrote:

I appreciate the time you've taken to answer Shay. ElasticSearch is
great.

I'm using the Java API.

How would I go about producing multiple mappings for a single field?
or do you mean having two fields with only one being analysed? And how
do I go about choosing which mapping to use when querying/filtering?

You say "doing phrase searches, or sloppy phrase searches are
certainly possible." Which of my examples do these relate to and how
would I go about implementing this?

I may have misunderstood, but if phrase searches are possible (and by
this I mean "ipsum dolor" is matched, but "dolour ipsum" is not in the
above example), then why is a full "equal to" not possible on the same
analysed field?

Thanks

On Sep 21, 12:19 am, Shay Banon kim...@gmail.com wrote:

Hey,

You can use the text query (which analyzes the text you search on) for
simple text matches:
http://www.elasticsearch.org/guide/reference/query-dsl/text-query.html.

Doing an "equal to" on an analyzed fields that gets broken down into
multiple terms is not really possible, but doing phrase searches, or
sloppy
phrase searches are certainly possible.

For exact matching, you could have a multi field mapping, with a non
analyzed option on the field, and search against that.

-shay.banon

On Wed, Sep 21, 2011 at 12:22 AM, marcuslongmuir <marcuslongm...@me.com
wrote:

I've been using ElasticSearch for a while, but I haven't really dug
into the text search side of things. I went to implement really simple
text searching earlier today and got a bit confused.

From what I understand I can't do a "Whole text value is equal to
search parameter" query because the text was analysed when it was
indexed and doesn't exist in it's whole form? If someone could explain
how to get the following working I'd be very grateful:

Index a piece of text:
"Lorem ipsum dolor sit amet"

And be able to retrieve the document with the following queries:
Phrase: "ipsum dolor"
Contains: "sit"
EqualTo: "Lorem ipsum dolor sit amet"

But not retrieve the document for the following queries:
Phrase: "dolor ipsum"
EqualTo: "dolor sit"

I don't really want users to be able to use keywords in the strings
for the sake of unwanted confusion so keywords like "and" and "or"
should either be ignored or actually searched for rather than being
operators.

Thanks for any advice


(shuaib) #6

hai,

I am new to elastic search. I would like to have a simple example that work in java.so that I can implement in my web application.

Shuaib Kunhabdulla
eteam india pvt ltd
technopark
india


(system) #7