# Really simple text searching

**URL:** <https://discuss.elastic.co/t/really-simple-text-searching/5418>\
**Category:** Elasticsearch\
**Created:** [September 20, 2011, 9:22pm UTC](https://discuss.elastic.co/t/really-simple-text-searching/5418 "2011-09-20T21:22:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcusLongmuir](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@MarcusLongmuir](https://discuss.elastic.co/u/MarcusLongmuir)\
**Post date:** [September 20, 2011, 9:22pm UTC](https://discuss.elastic.co/t/really-simple-text-searching/5418/1 "2011-09-20T21:22:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [September 20, 2011, 11:19pm UTC](https://discuss.elastic.co/t/really-simple-text-searching/5418/2 "2011-09-20T23:19:00Z")

</div>

Hey,

You can use the text query (which analyzes the text you search on) for  
simple text matches:  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](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.com](mailto:marcuslongmuir@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

---

<div class="post-metadata">

**Author:** ![MarcusLongmuir](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@MarcusLongmuir](https://discuss.elastic.co/u/MarcusLongmuir)\
**Post date:** [September 21, 2011, 5:18pm UTC](https://discuss.elastic.co/t/really-simple-text-searching/5418/3 "2011-09-21T17:18:22Z")

</div>

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](mailto:kim...@gmail.com) wrote:

> Hey,
> 
> You can use the text query (which analyzes the text you search on) for  
> simple text matches:[Elasticsearch Platform — Find real-time answers at scale | Elastic](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](mailto: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

---

<div class="post-metadata">

**Author:** ![Jan\_Fiedler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jan_fiedler/32/2518_2.png) [@Jan\_Fiedler](https://discuss.elastic.co/u/Jan_Fiedler)\
**Post date:** [September 21, 2011, 9:42pm UTC](https://discuss.elastic.co/t/really-simple-text-searching/5418/4 "2011-09-21T21:42:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [September 26, 2011, 10:53am UTC](https://discuss.elastic.co/t/really-simple-text-searching/5418/5 "2011-09-26T10:53:08Z")

</div>

You can do multiple mapping for a field using the multi\_field mapping type:  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](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.com](mailto:marcuslongmuir@me.com)wrote:

> 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](mailto:kim...@gmail.com) wrote:
> 
> > Hey,
> > 
> > You can use the text query (which analyzes the text you search on) for  
> > simple text matches:  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](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](mailto: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

---

<div class="post-metadata">

**Author:** ![shuaib](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@shuaib](https://discuss.elastic.co/u/shuaib)\
**Post date:** [December 3, 2013, 9:13am UTC](https://discuss.elastic.co/t/really-simple-text-searching/5418/6 "2013-12-03T09:13:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:03am UTC](https://discuss.elastic.co/t/really-simple-text-searching/5418/7 "2017-07-06T02:03:44Z")

</div>


