# Exact Match Query on analyzed field

**URL:** <https://discuss.elastic.co/t/exact-match-query-on-analyzed-field/1440>\
**Category:** Elasticsearch\
**Created:** [May 28, 2015, 6:03am UTC](https://discuss.elastic.co/t/exact-match-query-on-analyzed-field/1440 "2015-05-28T06:03:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ananth](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@ananth](https://discuss.elastic.co/u/ananth)\
**Post date:** [May 28, 2015, 6:03am UTC](https://discuss.elastic.co/t/exact-match-query-on-analyzed-field/1440/1 "2015-05-28T06:03:23Z")

</div>

Hi ,

I have an analysed field , it may have different values for each documents. For example ,

doc1 : { "field1" : "abc01 - ([http://abc01.com/](http://abc01.com/))" }  
doc2 : { "field1" : "abc02 - ([http://abc02.com/](http://abc02.com/))" }  
doc3 : { "field1" : "-" }

The following is my analysis settings,  
index :  
analysis :  
analyzer :  
default\_index :  
type : custom  
tokenizer : whitespace  
filter : [word\_delimiter, snowball, lowercase]  
default\_search :  
type : custom  
tokenizer : whitespace  
filter : [word\_delimiter, snowball, lowercase]  
filter :  
word\_delimiter :  
type : word\_delimiter  
preserve\_original : true  
split\_on\_numerics : true  
stem\_english\_possessive : false

I need to filter documents which has only "-" ? i.e.. is it possible query only doc3 (no other terms other than "-")? since doc1 & doc2 also has "-" along with some other terms.

One solution i know is ,  
Syntax: boolQuery.must("-") + boolQuery.mustNot("abc\*" )  
Here too i production mode, i couldn't find all other terms which i need to specify in not query.

---

<div class="post-metadata">

**Author:** ![Jason\_Wee](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@Jason\_Wee](https://discuss.elastic.co/u/Jason_Wee)\
**Post date:** [May 29, 2015, 5:51pm UTC](https://discuss.elastic.co/t/exact-match-query-on-analyzed-field/1440/2 "2015-05-29T17:51:49Z")

</div>

just my two cents.

create index

```
curl -XPUT 'http://localhost:9200/my_index?pretty' -d ' {
    "settings": {
        "number_of_shards": 5,
        "analysis": {
            "analyzer" : {
               "my_analyzer" : {
                    "type" : "custom",
                    "tokenizer" : "whitespace"
               }
            }
        }
    }
}'

```

create mapping on type and field1

```
curl -XPUT 'http://localhost:9200/my_index/_mapping/my_type?pretty' -d '
{
    "my_type": {
        "properties": {
            "field1": {
                "type": "string",
                "analyzer": "whitespace"
            }
        }
    }
}'

```

index sample data

```
curl -XPOST 'http://localhost:9200/my_index/my_type/_bulk?pretty' -d ' 
{ "index": { "_id": 1 }}
{ "field1": "abc01 - (http://abc01.com/)" }
{ "index": { "_id": 2 }}
{ "field1": "abc02 - (http://abc02.com/)" }
{ "index": { "_id": 3 }}
{ "field1": "-" }
'

```

query 😄

```
curl -XGET 'http://localhost:9200/my_index/_search?pretty' -d '
{
   "query" : {
     "bool" : {
        "must" : {
            "term" : { "field1" : "-" }
        },
        "must_not" : {
            "query_string" : {
                "default_field" : "field1",
                "query" : "abc*"
            }
        }
    }
   }
}'

```

hth

jason

---

<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, 12:10am UTC](https://discuss.elastic.co/t/exact-match-query-on-analyzed-field/1440/3 "2017-07-06T00:10:46Z")

</div>


