# Beginner's question about searching

**URL:** <https://discuss.elastic.co/t/beginners-question-about-searching/3861>\
**Category:** Elasticsearch\
**Created:** [February 1, 2011, 11:36pm UTC](https://discuss.elastic.co/t/beginners-question-about-searching/3861 "2011-02-01T23:36:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enrique\_Medina\_Monte](https://avatars.discourse-cdn.com/v4/letter/e/4491bb/32.png) [@Enrique\_Medina\_Monte](https://discuss.elastic.co/u/Enrique_Medina_Monte)\
**Post date:** [February 1, 2011, 11:36pm UTC](https://discuss.elastic.co/t/beginners-question-about-searching/3861/1 "2011-02-01T23:36:17Z")

</div>

Hi,

I know this may sound as a beginner's question to searching in ES, but I  
just want to make sure I get it.

Which is the type of query that I should use on searching coincidence terms  
(for instance, I have indexed lots of products, and I want to look by  
words):

a) Term --\> But in the doc it says that this one is used for "not analyzed"  
fields.  
b) Wildcard --\> Seems to work fine, but for some reason it doesn't return  
the exact matches. For example, if you're looking for "iphone" and then you  
define the wildcard value as "iphone\*", then it won't return any product  
with "iphone" whatsoever.  
c) Fuzzy --\> This seems to be the closest to a typical search by words. So  
if I search with "iphone", then it will also find "phone", "telephone", even  
"microphone".

So which one should be used in each case? Could someone post some simple  
usage scenarios for each type of query?

Thanks.

---

<div class="post-metadata">

**Author:** ![Enrique\_Medina\_Monte](https://avatars.discourse-cdn.com/v4/letter/e/4491bb/32.png) [@Enrique\_Medina\_Monte](https://discuss.elastic.co/u/Enrique_Medina_Monte)\
**Post date:** [February 2, 2011, 11:35am UTC](https://discuss.elastic.co/t/beginners-question-about-searching/3861/2 "2011-02-02T11:35:17Z")

</div>

Any feedback on the below?

On Wed, Feb 2, 2011 at 12:36 AM, Enrique Medina Montenegro \<  
[e.medina.m@gmail.com](mailto:e.medina.m@gmail.com)\> wrote:

> Hi,
> 
> I know this may sound as a beginner's question to searching in ES, but I  
> just want to make sure I get it.
> 
> Which is the type of query that I should use on searching coincidence terms  
> (for instance, I have indexed lots of products, and I want to look by  
> words):
> 
> a) Term --\> But in the doc it says that this one is used for "not analyzed"  
> fields.  
> b) Wildcard --\> Seems to work fine, but for some reason it doesn't return  
> the exact matches. For example, if you're looking for "iphone" and then you  
> define the wildcard value as "iphone\*", then it won't return any product  
> with "iphone" whatsoever.  
> c) Fuzzy --\> This seems to be the closest to a typical search by words. So  
> if I search with "iphone", then it will also find "phone", "telephone", even  
> "microphone".
> 
> So which one should be used in each case? Could someone post some simple  
> usage scenarios for each type of query?
> 
> Thanks.

---

<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:** [February 2, 2011, 12:18pm UTC](https://discuss.elastic.co/t/beginners-question-about-searching/3861/3 "2011-02-02T12:18:52Z")

</div>

The simplest is to use the field query, which also analyzes the query string provided (breaks it into terms).  
On Wednesday, February 2, 2011 at 1:35 PM, Enrique Medina Montenegro wrote:

> Any feedback on the below?
> 
> On Wed, Feb 2, 2011 at 12:36 AM, Enrique Medina Montenegro [e.medina.m@gmail.com](mailto:e.medina.m@gmail.com) wrote:
> 
> > Hi,
> > 
> > I know this may sound as a beginner's question to searching in ES, but I just want to make sure I get it.
> > 
> > Which is the type of query that I should use on searching coincidence terms (for instance, I have indexed lots of products, and I want to look by words):
> > 
> > a) Term --\> But in the doc it says that this one is used for "not analyzed" fields.  
> > b) Wildcard --\> Seems to work fine, but for some reason it doesn't return the exact matches. For example, if you're looking for "iphone" and then you define the wildcard value as "iphone\*", then it won't return any product with "iphone" whatsoever.  
> > c) Fuzzy --\> This seems to be the closest to a typical search by words. So if I search with "iphone", then it will also find "phone", "telephone", even "microphone".
> > 
> > So which one should be used in each case? Could someone post some simple usage scenarios for each type of query?
> > 
> > Thanks.

---

<div class="post-metadata">

**Author:** ![Enrique\_Medina\_Monte](https://avatars.discourse-cdn.com/v4/letter/e/4491bb/32.png) [@Enrique\_Medina\_Monte](https://discuss.elastic.co/u/Enrique_Medina_Monte)\
**Post date:** [February 2, 2011, 12:25pm UTC](https://discuss.elastic.co/t/beginners-question-about-searching/3861/4 "2011-02-02T12:25:26Z")

</div>

But Shay, the results I get with using Fuzzy compared to Field query are  
quite different.

This is in Spanish, but for instance, if I select Field query, then the term  
provided by the user must be as close as possible to the original term in  
the document indexed. For example:

"Crema para maquillarse de uso casero"

If I use Field query with term = "maquillaje", then I don't get that result  
above ("maquillaje" is a noun, whereas "maquillarse" is the action verb for  
the noun).

But if I use Fuzzy query with same term, then I do get it (and probably some  
noise, but with lower scores).

What do you think? I'd just like to set my user's expectations here  
beforehand.

On Wed, Feb 2, 2011 at 1:18 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> The simplest is to use the field query, which also analyzes the query  
> string provided (breaks it into terms).
> 
> On Wednesday, February 2, 2011 at 1:35 PM, Enrique Medina Montenegro wrote:
> 
> Any feedback on the below?
> 
> On Wed, Feb 2, 2011 at 12:36 AM, Enrique Medina Montenegro \<  
> [e.medina.m@gmail.com](mailto:e.medina.m@gmail.com)\> wrote:
> 
> Hi,
> 
> I know this may sound as a beginner's question to searching in ES, but I  
> just want to make sure I get it.
> 
> Which is the type of query that I should use on searching coincidence terms  
> (for instance, I have indexed lots of products, and I want to look by  
> words):
> 
> a) Term --\> But in the doc it says that this one is used for "not analyzed"  
> fields.  
> b) Wildcard --\> Seems to work fine, but for some reason it doesn't return  
> the exact matches. For example, if you're looking for "iphone" and then you  
> define the wildcard value as "iphone\*", then it won't return any product  
> with "iphone" whatsoever.  
> c) Fuzzy --\> This seems to be the closest to a typical search by words. So  
> if I search with "iphone", then it will also find "phone", "telephone", even  
> "microphone".
> 
> So which one should be used in each case? Could someone post some simple  
> usage scenarios for each type of query?
> 
> Thanks.

---

<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:** [February 2, 2011, 12:27pm UTC](https://discuss.elastic.co/t/beginners-question-about-searching/3861/5 "2011-02-02T12:27:09Z")

</div>

This depends on your analyzer, which is used to break the provided text into tokens when you use field query.  
On Wednesday, February 2, 2011 at 2:25 PM, Enrique Medina Montenegro wrote:

> But Shay, the results I get with using Fuzzy compared to Field query are quite different.
> 
> This is in Spanish, but for instance, if I select Field query, then the term provided by the user must be as close as possible to the original term in the document indexed. For example:
> 
> "Crema para maquillarse de uso casero"
> 
> If I use Field query with term = "maquillaje", then I don't get that result above ("maquillaje" is a noun, whereas "maquillarse" is the action verb for the noun).
> 
> But if I use Fuzzy query with same term, then I do get it (and probably some noise, but with lower scores).
> 
> What do you think? I'd just like to set my user's expectations here beforehand.
> 
> On Wed, Feb 2, 2011 at 1:18 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:
> 
> > The simplest is to use the field query, which also analyzes the query string provided (breaks it into terms).  
> > On Wednesday, February 2, 2011 at 1:35 PM, Enrique Medina Montenegro wrote:
> > 
> > > Any feedback on the below?
> > > 
> > > On Wed, Feb 2, 2011 at 12:36 AM, Enrique Medina Montenegro [e.medina.m@gmail.com](mailto:e.medina.m@gmail.com) wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I know this may sound as a beginner's question to searching in ES, but I just want to make sure I get it.
> > > > 
> > > > Which is the type of query that I should use on searching coincidence terms (for instance, I have indexed lots of products, and I want to look by words):
> > > > 
> > > > a) Term --\> But in the doc it says that this one is used for "not analyzed" fields.  
> > > > b) Wildcard --\> Seems to work fine, but for some reason it doesn't return the exact matches. For example, if you're looking for "iphone" and then you define the wildcard value as "iphone\*", then it won't return any product with "iphone" whatsoever.  
> > > > c) Fuzzy --\> This seems to be the closest to a typical search by words. So if I search with "iphone", then it will also find "phone", "telephone", even "microphone".
> > > > 
> > > > So which one should be used in each case? Could someone post some simple usage scenarios for each type of query?
> > > > 
> > > > Thanks.

---

<div class="post-metadata">

**Author:** ![Enrique\_Medina\_Monte](https://avatars.discourse-cdn.com/v4/letter/e/4491bb/32.png) [@Enrique\_Medina\_Monte](https://discuss.elastic.co/u/Enrique_Medina_Monte)\
**Post date:** [February 2, 2011, 12:37pm UTC](https://discuss.elastic.co/t/beginners-question-about-searching/3861/6 "2011-02-02T12:37:10Z")

</div>

Shay,

I'm using the same analyzer that I was using before with just Lucene (with  
Compass), which is:

@SuppressWarnings({ "unchecked", "rawtypes" })

_public_ TokenStream tokenStream(String fieldName, Reader reader) {

TokenStream result = _new_ StandardTokenizer(Version.LUCENE\_30, reader);

result = _new_ StandardFilter(result);

result = _new_ LowerCaseFilter(result);

result = _new_ ASCIIFoldingFilter(result); // Mi cambio

result = _new_ StopFilter(_false_, result, _new_ HashSet(Arrays.asList(  
SPANISH\_STOP\_WORDS)));

result = _new_ SnowballFilter(result, "Spanish");

_return_ result;

}

A quick comparison of results showed that searches in "old" Lucene version  
where not the same as in ES with the same analyzer, so that's why I started  
to change the types of query, and came up with Fuzzy being the most similar  
to "old" behaviour, but as Fuzzy is something which should onlu be used in  
specific scenarios (due to the fuzziness of the search itself), tht's why I  
wanted to double check with the list here...

On Wed, Feb 2, 2011 at 1:27 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> This depends on your analyzer, which is used to break the provided text  
> into tokens when you use field query.
> 
> On Wednesday, February 2, 2011 at 2:25 PM, Enrique Medina Montenegro wrote:
> 
> But Shay, the results I get with using Fuzzy compared to Field query are  
> quite different.
> 
> This is in Spanish, but for instance, if I select Field query, then the  
> term provided by the user must be as close as possible to the original term  
> in the document indexed. For example:
> 
> "Crema para maquillarse de uso casero"
> 
> If I use Field query with term = "maquillaje", then I don't get that result  
> above ("maquillaje" is a noun, whereas "maquillarse" is the action verb for  
> the noun).
> 
> But if I use Fuzzy query with same term, then I do get it (and probably  
> some noise, but with lower scores).
> 
> What do you think? I'd just like to set my user's expectations here  
> beforehand.
> 
> On Wed, Feb 2, 2011 at 1:18 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> The simplest is to use the field query, which also analyzes the query  
> string provided (breaks it into terms).
> 
> On Wednesday, February 2, 2011 at 1:35 PM, Enrique Medina Montenegro wrote:
> 
> Any feedback on the below?
> 
> On Wed, Feb 2, 2011 at 12:36 AM, Enrique Medina Montenegro \<  
> [e.medina.m@gmail.com](mailto:e.medina.m@gmail.com)\> wrote:
> 
> Hi,
> 
> I know this may sound as a beginner's question to searching in ES, but I  
> just want to make sure I get it.
> 
> Which is the type of query that I should use on searching coincidence terms  
> (for instance, I have indexed lots of products, and I want to look by  
> words):
> 
> a) Term --\> But in the doc it says that this one is used for "not analyzed"  
> fields.  
> b) Wildcard --\> Seems to work fine, but for some reason it doesn't return  
> the exact matches. For example, if you're looking for "iphone" and then you  
> define the wildcard value as "iphone\*", then it won't return any product  
> with "iphone" whatsoever.  
> c) Fuzzy --\> This seems to be the closest to a typical search by words. So  
> if I search with "iphone", then it will also find "phone", "telephone", even  
> "microphone".
> 
> So which one should be used in each case? Could someone post some simple  
> usage scenarios for each type of query?
> 
> Thanks.

---

<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:** [February 2, 2011, 1:06pm UTC](https://discuss.elastic.co/t/beginners-question-about-searching/3861/7 "2011-02-02T13:06:14Z")

</div>

Have you made sure to use a new index once you defined the analyzer and reindex the data so it will use it?  
On Wednesday, February 2, 2011 at 2:37 PM, Enrique Medina Montenegro wrote:

> Shay,
> 
> I'm using the same analyzer that I was using before with just Lucene (with Compass), which is:
> 
> @SuppressWarnings({ "unchecked", "rawtypes" })  
> public TokenStream tokenStream(String fieldName, Reader reader) {  
> TokenStream result = new StandardTokenizer(Version.LUCENE\_30, reader);  
> result = new StandardFilter(result);  
> result = new LowerCaseFilter(result);  
> result = new ASCIIFoldingFilter(result); // Mi cambio  
> result = new StopFilter(false, result, new HashSet(Arrays.asList(SPANISH\_STOP\_WORDS)));  
> result = new SnowballFilter(result, "Spanish");  
> return result;  
> }
> 
> A quick comparison of results showed that searches in "old" Lucene version where not the same as in ES with the same analyzer, so that's why I started to change the types of query, and came up with Fuzzy being the most similar to "old" behaviour, but as Fuzzy is something which should onlu be used in specific scenarios (due to the fuzziness of the search itself), tht's why I wanted to double check with the list here...
> 
> On Wed, Feb 2, 2011 at 1:27 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:
> 
> > This depends on your analyzer, which is used to break the provided text into tokens when you use field query.  
> > On Wednesday, February 2, 2011 at 2:25 PM, Enrique Medina Montenegro wrote:
> > 
> > > But Shay, the results I get with using Fuzzy compared to Field query are quite different.
> > > 
> > > This is in Spanish, but for instance, if I select Field query, then the term provided by the user must be as close as possible to the original term in the document indexed. For example:
> > > 
> > > "Crema para maquillarse de uso casero"
> > > 
> > > If I use Field query with term = "maquillaje", then I don't get that result above ("maquillaje" is a noun, whereas "maquillarse" is the action verb for the noun).
> > > 
> > > But if I use Fuzzy query with same term, then I do get it (and probably some noise, but with lower scores).
> > > 
> > > What do you think? I'd just like to set my user's expectations here beforehand.
> > > 
> > > On Wed, Feb 2, 2011 at 1:18 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:
> > > 
> > > > The simplest is to use the field query, which also analyzes the query string provided (breaks it into terms).  
> > > > On Wednesday, February 2, 2011 at 1:35 PM, Enrique Medina Montenegro wrote:
> > > > 
> > > > > Any feedback on the below?
> > > > > 
> > > > > On Wed, Feb 2, 2011 at 12:36 AM, Enrique Medina Montenegro [e.medina.m@gmail.com](mailto:e.medina.m@gmail.com) wrote:
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > I know this may sound as a beginner's question to searching in ES, but I just want to make sure I get it.
> > > > > > 
> > > > > > Which is the type of query that I should use on searching coincidence terms (for instance, I have indexed lots of products, and I want to look by words):
> > > > > > 
> > > > > > a) Term --\> But in the doc it says that this one is used for "not analyzed" fields.  
> > > > > > b) Wildcard --\> Seems to work fine, but for some reason it doesn't return the exact matches. For example, if you're looking for "iphone" and then you define the wildcard value as "iphone\*", then it won't return any product with "iphone" whatsoever.  
> > > > > > c) Fuzzy --\> This seems to be the closest to a typical search by words. So if I search with "iphone", then it will also find "phone", "telephone", even "microphone".
> > > > > > 
> > > > > > So which one should be used in each case? Could someone post some simple usage scenarios for each type of query?
> > > > > > 
> > > > > > Thanks.

---

<div class="post-metadata">

**Author:** ![Enrique\_Medina\_Monte](https://avatars.discourse-cdn.com/v4/letter/e/4491bb/32.png) [@Enrique\_Medina\_Monte](https://discuss.elastic.co/u/Enrique_Medina_Monte)\
**Post date:** [February 2, 2011, 1:13pm UTC](https://discuss.elastic.co/t/beginners-question-about-searching/3861/8 "2011-02-02T13:13:19Z")

</div>

Actually I'm creating a new index and analyzing everything from scratch, so  
it's sure that everything in ES is being analyzed with that spanish  
analyzer.

On Wed, Feb 2, 2011 at 2:06 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> Have you made sure to use a new index once you defined the analyzer and  
> reindex the data so it will use it?
> 
> On Wednesday, February 2, 2011 at 2:37 PM, Enrique Medina Montenegro wrote:
> 
> Shay,
> 
> I'm using the same analyzer that I was using before with just Lucene (with  
> Compass), which is:
> 
> @SuppressWarnings({ "unchecked", "rawtypes" })
> 
> _public_ TokenStream tokenStream(String fieldName, Reader reader) {
> 
> TokenStream result = _new_ StandardTokenizer(Version.LUCENE\_30, reader);
> 
> result = _new_ StandardFilter(result);
> 
> result = _new_ LowerCaseFilter(result);
> 
> result = _new_ ASCIIFoldingFilter(result); // Mi cambio
> 
> result = _new_ StopFilter(_false_, result, _new_ HashSet(Arrays.asList(  
> SPANISH\_STOP\_WORDS)));
> 
> result = _new_ SnowballFilter(result, "Spanish");
> 
> _return_ result;
> 
> }
> 
> A quick comparison of results showed that searches in "old" Lucene version  
> where not the same as in ES with the same analyzer, so that's why I started  
> to change the types of query, and came up with Fuzzy being the most similar  
> to "old" behaviour, but as Fuzzy is something which should onlu be used in  
> specific scenarios (due to the fuzziness of the search itself), tht's why I  
> wanted to double check with the list here...
> 
> On Wed, Feb 2, 2011 at 1:27 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> This depends on your analyzer, which is used to break the provided text  
> into tokens when you use field query.
> 
> On Wednesday, February 2, 2011 at 2:25 PM, Enrique Medina Montenegro wrote:
> 
> But Shay, the results I get with using Fuzzy compared to Field query are  
> quite different.
> 
> This is in Spanish, but for instance, if I select Field query, then the  
> term provided by the user must be as close as possible to the original term  
> in the document indexed. For example:
> 
> "Crema para maquillarse de uso casero"
> 
> If I use Field query with term = "maquillaje", then I don't get that result  
> above ("maquillaje" is a noun, whereas "maquillarse" is the action verb for  
> the noun).
> 
> But if I use Fuzzy query with same term, then I do get it (and probably  
> some noise, but with lower scores).
> 
> What do you think? I'd just like to set my user's expectations here  
> beforehand.
> 
> On Wed, Feb 2, 2011 at 1:18 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> The simplest is to use the field query, which also analyzes the query  
> string provided (breaks it into terms).
> 
> On Wednesday, February 2, 2011 at 1:35 PM, Enrique Medina Montenegro wrote:
> 
> Any feedback on the below?
> 
> On Wed, Feb 2, 2011 at 12:36 AM, Enrique Medina Montenegro \<  
> [e.medina.m@gmail.com](mailto:e.medina.m@gmail.com)\> wrote:
> 
> Hi,
> 
> I know this may sound as a beginner's question to searching in ES, but I  
> just want to make sure I get it.
> 
> Which is the type of query that I should use on searching coincidence terms  
> (for instance, I have indexed lots of products, and I want to look by  
> words):
> 
> a) Term --\> But in the doc it says that this one is used for "not analyzed"  
> fields.  
> b) Wildcard --\> Seems to work fine, but for some reason it doesn't return  
> the exact matches. For example, if you're looking for "iphone" and then you  
> define the wildcard value as "iphone\*", then it won't return any product  
> with "iphone" whatsoever.  
> c) Fuzzy --\> This seems to be the closest to a typical search by words. So  
> if I search with "iphone", then it will also find "phone", "telephone", even  
> "microphone".
> 
> So which one should be used in each case? Could someone post some simple  
> usage scenarios for each type of query?
> 
> Thanks.

---

<div class="post-metadata">

**Author:** ![Enrique\_Medina\_Monte](https://avatars.discourse-cdn.com/v4/letter/e/4491bb/32.png) [@Enrique\_Medina\_Monte](https://discuss.elastic.co/u/Enrique_Medina_Monte)\
**Post date:** [February 2, 2011, 2:32pm UTC](https://discuss.elastic.co/t/beginners-question-about-searching/3861/9 "2011-02-02T14:32:26Z")

</div>

Shay,

I found a very clear example of what the difference could be by using Fuzzy  
or Field query. Let me explain.

I'm using a catalog of products where I'm just taking the name and  
description. I'm also using the Spanish analyzer that I pasted below in my  
previous email to analyze by default (with configuration you already  
confirmed in some other thread in this list). So far so good.

Now I index some thousands of products, where some of them have the term  
"calibration" as part of the name. This term translated to spanish is  
"calibración" (so pretty similar).

After having indexed everything, I start my search (using REST API):

a) If I use the Field query, then when I search for exact match  
"calibración", I don't get any results:

# Filter query:

{

```
"from" : 0, "size" : 1000,

"query" : {

```

"field" : {

"nombre" : {

"query" : "calibración"

}

}

}

}

# Result JSON:

[{

"hits": {

```
"hits": [],

"max_score": null,

"total": 0

```

},

"timed\_out": false,

"took": 1,

"\_shards": {

```
"failed": 0,

"total": 3,

"successful": 3

```

}

}]

Even if I add a '_' wildcard to the end, or both to the end and the  
beginning of the term, like "calibración_" or "_calibración_", I still don't  
get any results.

b) With the same Field query, now I just provide the root of the term plus a  
'_' wildcard, i.e. "calibra_":

# Filter query:

{

```
"from" : 0, "size" : 1000,

"query" : {

```

"field" : {

"nombre" : {

"query" : "calibra\*"

}

}

}

}

# Result JSON:

[{

"hits": {

```
"hits": [

  {

    "_source": {

      "descripcion": "Monitor 730 Lacie de 30\" para Mac & PC",

      "nombre": "LaCie 730 LCD Monitor + Hood + Calibration Software"

    },

    "_type": "producto",

    "_score": 1,

    "_id": "dXD8xKUFQKCv7jynZ7Z9EQ",

    "_version": 1,

    "_index": "cuestamenos"

  },

  {

    "_source": {

      "descripcion": "Monitor 724 Lacie de 24\" para Mac & PC",

      "nombre": "LaCie 724 LCD Monitor + Hood + Calibration Software"

    },

    "_type": "producto",

    "_score": 1,

    "_id": "3P6fLeuNTTusyj-Y99uAuQ",

    "_version": 1,

    "_index": "cuestamenos"

  },

  {

    "_source": {

      "descripcion": "Monitor 730 Lacie de 30\" para Mac & PC",

      "nombre": "LaCie 730 LCD Monitor + Hood + Calibration Software +

```

Colorimeter"

```
    },

    "_type": "producto",

    "_score": 1,

    "_id": "DH-JDVP1RlCvJ82KF7sHcQ",

    "_version": 1,

    "_index": "cuestamenos"

  },

```

.....

As you can see, I do get the expected results, but I had to trim the search  
term to the stem that matches the beginning of "calibration", which is  
"calibra" in this case. if I add a simple char like "calibrac\*" to my search  
term, it won't show any results again.

c) Now I switch to Fuzzy query, and look for exact word "calibración":

# Filter query:

{

```
"from" : 0, "size" : 1000,

"query" : {

```

"fuzzy" : { "nombre" : "calibración" }

}

}

}

# Result JSON:

[{

"hits": {

```
"hits": [

  {

    "_source": {

      "descripcion": "Monitor 730 Lacie de 30\" para Mac & PC",

      "nombre": "LaCie 730 LCD Monitor + Hood + Calibration Software"

    },

    "_type": "producto",

    "_score": 1,

    "_id": "dXD8xKUFQKCv7jynZ7Z9EQ",

    "_version": 1,

    "_index": "cuestamenos"

  },

  {

    "_source": {

      "descripcion": "Monitor 724 Lacie de 24\" para Mac & PC",

      "nombre": "LaCie 724 LCD Monitor + Hood + Calibration Software"

    },

    "_type": "producto",

    "_score": 1,

    "_id": "3P6fLeuNTTusyj-Y99uAuQ",

    "_version": 1,

    "_index": "cuestamenos"

  },

  {

    "_source": {

      "descripcion": "Monitor 730 Lacie de 30\" para Mac & PC",

      "nombre": "LaCie 730 LCD Monitor + Hood + Calibration Software +

```

Colorimeter"

```
    },

    "_type": "producto",

    "_score": 1,

    "_id": "DH-JDVP1RlCvJ82KF7sHcQ",

    "_version": 1,

    "_index": "cuestamenos"

  },

```

.....

As you can see, the Fuzzy query does return the expected results, as the  
spanish user might not know the english word for "calibración", but still  
wants to see those results (or at least expects so). And I don't have to  
stemmize the search term, but just pass it as the user enters it. Even if I  
use a search term like "calibrado" (which states for "calibrated" in  
english), it works as expected.

So why would we use the Field query which only seems to return matches when  
the stem of the search word is used in conjuction with a '\*' wildcard rather  
than the Fuzzy query, in general? Any feedback on this proof of concept?

Thanks!

On Wed, Feb 2, 2011 at 2:13 PM, Enrique Medina Montenegro \<  
[e.medina.m@gmail.com](mailto:e.medina.m@gmail.com)\> wrote:

> Actually I'm creating a new index and analyzing everything from scratch, so  
> it's sure that everything in ES is being analyzed with that spanish  
> analyzer.
> 
> On Wed, Feb 2, 2011 at 2:06 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> > Have you made sure to use a new index once you defined the analyzer and  
> > reindex the data so it will use it?
> > 
> > On Wednesday, February 2, 2011 at 2:37 PM, Enrique Medina Montenegro  
> > wrote:
> > 
> > Shay,
> > 
> > I'm using the same analyzer that I was using before with just Lucene (with  
> > Compass), which is:
> > 
> > @SuppressWarnings({ "unchecked", "rawtypes" })
> > 
> > _public_ TokenStream tokenStream(String fieldName, Reader reader) {
> > 
> > TokenStream result = _new_ StandardTokenizer(Version.LUCENE\_30, reader);
> > 
> > result = _new_ StandardFilter(result);
> > 
> > result = _new_ LowerCaseFilter(result);
> > 
> > result = _new_ ASCIIFoldingFilter(result); // Mi cambio
> > 
> > result = _new_ StopFilter(_false_, result, _new_ HashSet(Arrays.asList(  
> > SPANISH\_STOP\_WORDS)));
> > 
> > result = _new_ SnowballFilter(result, "Spanish");
> > 
> > _return_ result;
> > 
> > }
> > 
> > A quick comparison of results showed that searches in "old" Lucene version  
> > where not the same as in ES with the same analyzer, so that's why I started  
> > to change the types of query, and came up with Fuzzy being the most similar  
> > to "old" behaviour, but as Fuzzy is something which should onlu be used in  
> > specific scenarios (due to the fuzziness of the search itself), tht's why I  
> > wanted to double check with the list here...
> > 
> > On Wed, Feb 2, 2011 at 1:27 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> > 
> > This depends on your analyzer, which is used to break the provided text  
> > into tokens when you use field query.
> > 
> > On Wednesday, February 2, 2011 at 2:25 PM, Enrique Medina Montenegro  
> > wrote:
> > 
> > But Shay, the results I get with using Fuzzy compared to Field query are  
> > quite different.
> > 
> > This is in Spanish, but for instance, if I select Field query, then the  
> > term provided by the user must be as close as possible to the original term  
> > in the document indexed. For example:
> > 
> > "Crema para maquillarse de uso casero"
> > 
> > If I use Field query with term = "maquillaje", then I don't get that  
> > result above ("maquillaje" is a noun, whereas "maquillarse" is the action  
> > verb for the noun).
> > 
> > But if I use Fuzzy query with same term, then I do get it (and probably  
> > some noise, but with lower scores).
> > 
> > What do you think? I'd just like to set my user's expectations here  
> > beforehand.
> > 
> > On Wed, Feb 2, 2011 at 1:18 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> > 
> > The simplest is to use the field query, which also analyzes the query  
> > string provided (breaks it into terms).
> > 
> > On Wednesday, February 2, 2011 at 1:35 PM, Enrique Medina Montenegro  
> > wrote:
> > 
> > Any feedback on the below?
> > 
> > On Wed, Feb 2, 2011 at 12:36 AM, Enrique Medina Montenegro \<  
> > [e.medina.m@gmail.com](mailto:e.medina.m@gmail.com)\> wrote:
> > 
> > Hi,
> > 
> > I know this may sound as a beginner's question to searching in ES, but I  
> > just want to make sure I get it.
> > 
> > Which is the type of query that I should use on searching coincidence  
> > terms (for instance, I have indexed lots of products, and I want to look by  
> > words):
> > 
> > a) Term --\> But in the doc it says that this one is used for "not  
> > analyzed" fields.  
> > b) Wildcard --\> Seems to work fine, but for some reason it doesn't return  
> > the exact matches. For example, if you're looking for "iphone" and then you  
> > define the wildcard value as "iphone\*", then it won't return any product  
> > with "iphone" whatsoever.  
> > c) Fuzzy --\> This seems to be the closest to a typical search by words. So  
> > if I search with "iphone", then it will also find "phone", "telephone", even  
> > "microphone".
> > 
> > So which one should be used in each case? Could someone post some simple  
> > usage scenarios for each type of query?
> > 
> > Thanks.

---

<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, 4:12am UTC](https://discuss.elastic.co/t/beginners-question-about-searching/3861/10 "2017-07-06T04:12:52Z")

</div>


