# Exact phrase match question. (I know, another one)

**URL:** https://discuss.elastic.co/t/exact-phrase-match-question-i-know-another-one/8059
**Category:** Elasticsearch
**Created:** [June 12, 2012, 1:19pm UTC](https://discuss.elastic.co/t/exact-phrase-match-question-i-know-another-one/8059 "2012-06-12T13:19:09Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Tom\_Tayon\_2](https://avatars.discourse-cdn.com/v4/letter/t/f07891/32.png) [@Tom\_Tayon\_2](https://discuss.elastic.co/u/Tom_Tayon_2)
#### Post date: [June 12, 2012, 1:19pm UTC](https://discuss.elastic.co/t/exact-phrase-match-question-i-know-another-one/8059/1 "2012-06-12T13:19:09Z")

</div>

I seem to be having a problem getting an exact phrase match to work if  
it has a space in it.

I am using a multi-map field defined as:

VendorName: {  
type: multi\_field  
fields: {  
VendorName: {  
type: string  
}  
exact: {  
include\_in\_all: false  
analyzer: exact\_match  
type: string  
}  
}

The "exact\_match" analyzer is defined as:

```
index.analysis.analyzer.exact_match.type: custom
index.analysis.analyzer.exact_match.filter: lowercase
index.analysis.analyzer.exact_match.tokenizer: keyword

```

I am doing this because this needs to be case insensitive.

I have double checked this analyzer with:  
curl -XGET 'localhost:9200/test/\_analyze?analyzer=exact\_match' -d  
'This-is a test'

And the response is:  
{"tokens":[{"token":"this-is a test","start\_offset":0,"end\_offset":  
14,"type":"word","position":1}]}'  
which is what I expect.

I am building the query like this:

```
        String exactString = "\"this-is a\"";

        QueryStringQueryBuilder exactQuery =

```

QueryBuilders.queryString(exactString)  
.defaultOperator(Operator.AND);

```
        exactQuery.field("VendorName.exact");
        filter = FilterBuilders.queryFilter(exactQuery);

        AndFilterBuilder filters = new AndFilterBuilder();
        filter.add(filter);
        QueryBuilders.constantScoreQuery(filters);

```

I am building the And filters this way, because we can have rather  
complex searching, however, in this case, even just this one entry  
still doesn't work.

I have tried autoGeneratePhraseQueries() but that doesn't seem to do  
anything, so I am adding the "" myself.

The search performs flawlessly for any phrase I use, as long as it  
doesn't include a space. For instance, a "this-is" search works fine.

I have tried many different combinations of options, and I do believe  
this current configuration should work.

I am using version 0.19.4 in this test.

Thanks for your help,

Tom

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [June 12, 2012, 5:18pm UTC](https://discuss.elastic.co/t/exact-phrase-match-question-i-know-another-one/8059/2 "2012-06-12T17:18:22Z")

</div>

The name of the field should be simply "exact", not  
"VendorName.exact". You should also perhaps use a termQuery and not a  
queryString (lowercasing the query yourself.

On Tue, Jun 12, 2012 at 6:19 AM, Tom Tayon [tomtayon@gmail.com](mailto:tomtayon@gmail.com) wrote:

> I seem to be having a problem getting an exact phrase match to work if  
> it has a space in it.
> 
> I am using a multi-map field defined as:
> 
> VendorName: {  
> type: multi\_field  
> fields: {  
> VendorName: {  
> type: string  
> }  
> exact: {  
> include\_in\_all: false  
> analyzer: exact\_match  
> type: string  
> }  
> }
> 
> The "exact\_match" analyzer is defined as:
> 
> index.analysis.analyzer.exact\_match.type: custom  
> index.analysis.analyzer.exact\_match.filter: lowercase  
> index.analysis.analyzer.exact\_match.tokenizer: keyword
> 
> I am doing this because this needs to be case insensitive.
> 
> I have double checked this analyzer with:  
> curl -XGET 'localhost:9200/test/\_analyze?analyzer=exact\_match' -d  
> 'This-is a test'
> 
> And the response is:  
> {"tokens":[{"token":"this-is a test","start\_offset":0,"end\_offset":  
> 14,"type":"word","position":1}]}'  
> which is what I expect.
> 
> I am building the query like this:
> 
> ```
> String exactString = "\"this-is a\"";
> 
> QueryStringQueryBuilder exactQuery =
> 
> ```
> 
> QueryBuilders.queryString(exactString)  
> .defaultOperator(Operator.AND);
> 
> ```
> exactQuery.field("VendorName.exact");
> filter = FilterBuilders.queryFilter(exactQuery);
> 
> AndFilterBuilder filters = new AndFilterBuilder();
> filter.add(filter);
> QueryBuilders.constantScoreQuery(filters);
> 
> ```
> 
> I am building the And filters this way, because we can have rather  
> complex searching, however, in this case, even just this one entry  
> still doesn't work.
> 
> I have tried autoGeneratePhraseQueries() but that doesn't seem to do  
> anything, so I am adding the "" myself.
> 
> The search performs flawlessly for any phrase I use, as long as it  
> doesn't include a space. For instance, a "this-is" search works fine.
> 
> I have tried many different combinations of options, and I do believe  
> this current configuration should work.
> 
> I am using version 0.19.4 in this test.
> 
> Thanks for your help,
> 
> Tom

---

<div class="post-metadata">

### Author: ![Tom\_Tayon\_2](https://avatars.discourse-cdn.com/v4/letter/t/f07891/32.png) [@Tom\_Tayon\_2](https://discuss.elastic.co/u/Tom_Tayon_2)
#### Post date: [June 12, 2012, 6:00pm UTC](https://discuss.elastic.co/t/exact-phrase-match-question-i-know-another-one/8059/3 "2012-06-12T18:00:40Z")

</div>

Ok, I will look into the termQuery.

I need to use VendorName.exact, because I don't also want the search  
to look into other fields I have, i.e. "Address". I need field  
specific searching.

Thanks

On Jun 12, 12:18 pm, Ivan Brusic [i...@brusic.com](mailto:i...@brusic.com) wrote:

> The name of the field should be simply "exact", not  
> "VendorName.exact". You should also perhaps use a termQuery and not a  
> queryString (lowercasing the query yourself.
> 
> On Tue, Jun 12, 2012 at 6:19 AM, Tom Tayon [tomta...@gmail.com](mailto:tomta...@gmail.com) wrote:
> 
> > I seem to be having a problem getting an exact phrase match to work if  
> > it has a space in it.
> 
> > I am using a multi-map field defined as:
> 
> > VendorName: {  
> > type: multi\_field  
> > fields: {  
> > VendorName: {  
> > type: string  
> > }  
> > exact: {  
> > include\_in\_all: false  
> > analyzer: exact\_match  
> > type: string  
> > }  
> > }
> 
> > The "exact\_match" analyzer is defined as:
> 
> > index.analysis.analyzer.exact\_match.type: custom  
> > index.analysis.analyzer.exact\_match.filter: lowercase  
> > index.analysis.analyzer.exact\_match.tokenizer: keyword
> 
> > I am doing this because this needs to be case insensitive.
> 
> > I have double checked this analyzer with:  
> > curl -XGET 'localhost:9200/test/\_analyze?analyzer=exact\_match' -d  
> > 'This-is a test'
> 
> > And the response is:  
> > {"tokens":[{"token":"this-is a test","start\_offset":0,"end\_offset":  
> > 14,"type":"word","position":1}]}'  
> > which is what I expect.
> 
> > I am building the query like this:
> 
> > ```
> > String exactString = "\"this-is a\"";
> > 
> > ```
> 
> > ```
> > QueryStringQueryBuilder exactQuery =
> > 
> > ```
> > 
> > QueryBuilders.queryString(exactString)  
> > .defaultOperator(Operator.AND);
> 
> > ```
> > exactQuery.field("VendorName.exact");
> > filter = FilterBuilders.queryFilter(exactQuery);
> > 
> > ```
> 
> > ```
> > AndFilterBuilder filters = new AndFilterBuilder();
> > filter.add(filter);
> > QueryBuilders.constantScoreQuery(filters);
> > 
> > ```
> 
> > I am building the And filters this way, because we can have rather  
> > complex searching, however, in this case, even just this one entry  
> > still doesn't work.
> 
> > I have tried autoGeneratePhraseQueries() but that doesn't seem to do  
> > anything, so I am adding the "" myself.
> 
> > The search performs flawlessly for any phrase I use, as long as it  
> > doesn't include a space. For instance, a "this-is" search works fine.
> 
> > I have tried many different combinations of options, and I do believe  
> > this current configuration should work.
> 
> > I am using version 0.19.4 in this test.
> 
> > Thanks for your help,
> 
> > Tom

---

<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:24am UTC](https://discuss.elastic.co/t/exact-phrase-match-question-i-know-another-one/8059/4 "2017-07-06T03:24:44Z")

</div>


