# Matching a document against a keyword - exact "substring" match between document and keywords

**URL:** https://discuss.elastic.co/t/matching-a-document-against-a-keyword-exact-substring-match-between-document-and-keywords/6486
**Category:** Elasticsearch
**Created:** [January 25, 2012, 2:06am UTC](https://discuss.elastic.co/t/matching-a-document-against-a-keyword-exact-substring-match-between-document-and-keywords/6486 "2012-01-25T02:06:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Raul\_Jr\_Martinez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raul_jr_martinez/32/1286_2.png) [@Raul\_Jr\_Martinez](https://discuss.elastic.co/u/Raul_Jr_Martinez)
#### Post date: [January 25, 2012, 2:06am UTC](https://discuss.elastic.co/t/matching-a-document-against-a-keyword-exact-substring-match-between-document-and-keywords/6486/1 "2012-01-25T02:06:46Z")

</div>

Hello,

My goal is to ensure that only those document whose value exactly matches  
(including word position) some part/substring of the keywords.

To illustrate, I have a index/type that contains the following documents:

```
    ----- ----- ---------------------
    concept entity value
    ----- ----- ---------------------
    part part Mirror Motor           
    part brand Honda Collection       
    part brand Honda Apparel          
    vehicle make Honda                  
    part brand Honda by Moose         
    part part Mirror                 
    part part Telescoping Mirror     
    part part Mirror Back            
    part part Mirror Bra             
    part part Mirror Hardware        
    part part Mirror Mount           
    part part Spot Mirror            

```

I want to ensure that when the keywords is "Honda Civic Mirror" only the  
following documents are returned (or at least gets the highest \_score  
value)::

```
    vehicle make Honda                   
    part part Mirror                  

```

If the keywords is "Mirror Mount for Honda", only the following documents  
are to be returned (or at least gets the highest \_score value):

```
    vehicle make Honda                   
    part part Mirror Mount                

```

Is there any index and search analyzer that will allow me to achieve this  
goal?

Thanks,

Raul

---

<div class="post-metadata">

### Author: ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)
#### Post date: [January 25, 2012, 8:33am UTC](https://discuss.elastic.co/t/matching-a-document-against-a-keyword-exact-substring-match-between-document-and-keywords/6486/2 "2012-01-25T08:33:47Z")

</div>

Exact matching is a different thing ... doesn't the normal text query  
achieve what you want?

Peter.

On 25 Jan., 03:06, "Raul, Jr. Martinez" [jun...@gmail.com](mailto:jun...@gmail.com) wrote:

> Hello,
> 
> My goal is to ensure that only those document whose value exactly matches  
> (including word position) some part/substring of the keywords.
> 
> To illustrate, I have a index/type that contains the following documents:
> 
> ```
> ----- ----- ---------------------
> concept entity value
> ----- ----- ---------------------
> part part Mirror Motor
> part brand Honda Collection
> part brand Honda Apparel
> vehicle make Honda
> part brand Honda by Moose
> part part Mirror
> part part Telescoping Mirror
> part part Mirror Back
> part part Mirror Bra
> part part Mirror Hardware
> part part Mirror Mount
> part part Spot Mirror
> 
> ```
> 
> I want to ensure that when the keywords is "Honda Civic Mirror" only the  
> following documents are returned (or at least gets the highest \_score  
> value)::
> 
> ```
> vehicle make Honda
> part part Mirror
> 
> ```
> 
> If the keywords is "Mirror Mount for Honda", only the following documents  
> are to be returned (or at least gets the highest \_score value):
> 
> ```
> vehicle make Honda
> part part Mirror Mount
> 
> ```
> 
> Is there any index and search analyzer that will allow me to achieve this  
> goal?
> 
> Thanks,
> 
> Raul

---

<div class="post-metadata">

### Author: ![Raul\_Jr\_Martinez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raul_jr_martinez/32/1286_2.png) [@Raul\_Jr\_Martinez](https://discuss.elastic.co/u/Raul_Jr_Martinez)
#### Post date: [January 25, 2012, 9:22am UTC](https://discuss.elastic.co/t/matching-a-document-against-a-keyword-exact-substring-match-between-document-and-keywords/6486/3 "2012-01-25T09:22:31Z")

</div>

Hello Peter.

Normal text query works. I actually use query\_string. However when  
executing a query based on supplied keyword, the engine will actually try  
to whole or parts of the keywords against the searchable documents field.

Right now, with the current ES index that I have, searching for "Honda  
Civic Mirror" produces the following results:

* * *

concept entity value \_score

* * *

vehicle model Civic 0.638050  
vehicle make Honda 0.579641  
part brand Honda Collection 0.526310  
part brand Honda Apparel 0.524273  
part brand Honda by Moose 0.507186  
part part Mirror 0.476971  
vehicle model Civic del Sol 0.449377  
part part Mirror Arm 0.417349  
part part Mirror Switch 0.417349

I was hoping that to find a solution on excluding "part/brand = Honda  
Collection" to be not part of the list because in my keyword there is no  
word "Collection".

I am looking looking for the reverse of search ( but not using  
percolation). where document fields are checked to make sure that their  
value is a substring (or exact match) of the keywords. This should ensure  
that "Honda Collection" or "Mirror Arm" will not appear because "Arm" or  
"Collection" is not part of my example keywords.

* * *

concept entity value

* * *

vehicle model Civic  
vehicle make Honda  
part part Mirror

Wwhat I am looking for here is hard to explain, I apologize. I'm interested  
if someone out there has done something similar to this.

Regards,  
Raul

Regards,  
Raul

On Wed, Jan 25, 2012 at 4:33 PM, Karussell [tableyourtime@googlemail.com](mailto:tableyourtime@googlemail.com)wrote:

> Exact matching is a different thing ... doesn't the normal text query  
> achieve what you want?
> 
> Peter.
> 
> On 25 Jan., 03:06, "Raul, Jr. Martinez" [jun...@gmail.com](mailto:jun...@gmail.com) wrote:
> 
> > Hello,
> > 
> > My goal is to ensure that only those document whose value exactly matches  
> > (including word position) some part/substring of the keywords.
> > 
> > To illustrate, I have a index/type that contains the following documents:
> > 
> > ```
> > ----- ----- ---------------------
> > concept entity value
> > ----- ----- ---------------------
> > part part Mirror Motor
> > part brand Honda Collection
> > part brand Honda Apparel
> > vehicle make Honda
> > part brand Honda by Moose
> > part part Mirror
> > part part Telescoping Mirror
> > part part Mirror Back
> > part part Mirror Bra
> > part part Mirror Hardware
> > part part Mirror Mount
> > part part Spot Mirror
> > 
> > ```
> > 
> > I want to ensure that when the keywords is "Honda Civic Mirror" only the  
> > following documents are returned (or at least gets the highest \_score  
> > value)::
> > 
> > ```
> > vehicle make Honda
> > part part Mirror
> > 
> > ```
> > 
> > If the keywords is "Mirror Mount for Honda", only the following documents  
> > are to be returned (or at least gets the highest \_score value):
> > 
> > ```
> > vehicle make Honda
> > part part Mirror Mount
> > 
> > ```
> > 
> > Is there any index and search analyzer that will allow me to achieve this  
> > goal?
> > 
> > Thanks,
> > 
> > Raul

---

<div class="post-metadata">

### Author: ![rqueen](https://avatars.discourse-cdn.com/v4/letter/r/8dc957/32.png) [@rqueen](https://discuss.elastic.co/u/rqueen)
#### Post date: [March 24, 2012, 12:37pm UTC](https://discuss.elastic.co/t/matching-a-document-against-a-keyword-exact-substring-match-between-document-and-keywords/6486/4 "2012-03-24T12:37:48Z")

</div>

Hi Raul,  
Am looking for same scenario which you expected results.Can you suggest me how you solved the same search issue.  
it's very urgent for me

---

<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, 3:35am UTC](https://discuss.elastic.co/t/matching-a-document-against-a-keyword-exact-substring-match-between-document-and-keywords/6486/5 "2017-07-06T03:35:01Z")

</div>


