# Keyword type can't use field:(value1 value2) in querystring

**URL:** <https://discuss.elastic.co/t/keyword-type-cant-use-field-value1-value2-in-querystring/128279>\
**Category:** Elasticsearch\
**Created:** [April 17, 2018, 3:25am UTC](https://discuss.elastic.co/t/keyword-type-cant-use-field-value1-value2-in-querystring/128279 "2018-04-17T03:25:02Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![laigood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/laigood/32/30060_2.png) [@laigood](https://discuss.elastic.co/u/laigood)\
**Post date:** [April 17, 2018, 3:25am UTC](https://discuss.elastic.co/t/keyword-type-cant-use-field-value1-value2-in-querystring/128279/1 "2018-04-17T03:25:02Z")

</div>

I have a Keyword type field,and can use querystring field:(value1 OR value2) get the result,but if remove the 'OR' it return empty.even though i set default\_operator to "OR" in the querystring body,it still no effect,why?My es version is 6.2.2

full recreation script :

put mapping  
`PUT test/test/_mappings { "properties": { "test": { "type": "keyword" } } }`  
post docs  
`POST test/test/1 { "test": "1" } POST test/test/2 { "test": "2" }`  
and finally search  
`GET test/_search?q=test:(1 OR 2)`  
can get the result  
`{ "took": 13, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 2, "max_score": 0.2876821, "hits": [{ "_index": "test", "_type": "test", "_id": "2", "_score": 0.2876821, "_source": { "test": "2" } }, { "_index": "test", "_type": "test", "_id": "1", "_score": 0.2876821, "_source": { "test": "1" } }] } }`  
if i try  
`GET test/_search?q=test:(1 2)`  
it return rmpty

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 17, 2018, 3:52am UTC](https://discuss.elastic.co/t/keyword-type-cant-use-field-value1-value2-in-querystring/128279/2 "2018-04-17T03:52:24Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![laigood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/laigood/32/30060_2.png) [@laigood](https://discuss.elastic.co/u/laigood)\
**Post date:** [April 17, 2018, 7:08am UTC](https://discuss.elastic.co/t/keyword-type-cant-use-field-value1-value2-in-querystring/128279/3 "2018-04-17T07:08:26Z")

</div>

If i not put mapping first,and just post the data,it auto generate mapping like this:  
"test": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
}  
and this situation can work both test/\_search?q=test:(1 2) or test/\_search?q=test:(1 OR 2) . So what's different between type keyword to type keyword in type text

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 17, 2018, 7:24am UTC](https://discuss.elastic.co/t/keyword-type-cant-use-field-value1-value2-in-querystring/128279/4 "2018-04-17T07:24:59Z")

</div>

Difference is when you index something like "1 2 3" for example. With keyword you can search only for "1 2 3" where with text you can search for "1", "2", "3" for example.

---

<div class="post-metadata">

**Author:** ![laigood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/laigood/32/30060_2.png) [@laigood](https://discuss.elastic.co/u/laigood)\
**Post date:** [April 17, 2018, 7:35am UTC](https://discuss.elastic.co/t/keyword-type-cant-use-field-value1-value2-in-querystring/128279/5 "2018-04-17T07:35:49Z")

</div>

I know this,my situation is index doc1 with "1" and doc2 with "2".With keyword i can search by querystring field:(1 OR 2),but can't get result by search field:(1 2),in querystring this is the same query.  
With text i can search two doc in both method.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 17, 2018, 7:52am UTC](https://discuss.elastic.co/t/keyword-type-cant-use-field-value1-value2-in-querystring/128279/6 "2018-04-17T07:52:41Z")

</div>

As I already said:

> Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.
> 
> A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![laigood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/laigood/32/30060_2.png) [@laigood](https://discuss.elastic.co/u/laigood)\
**Post date:** [April 17, 2018, 8:01am UTC](https://discuss.elastic.co/t/keyword-type-cant-use-field-value1-value2-in-querystring/128279/7 "2018-04-17T08:01:24Z")

</div>

PUT test  
PUT test/test/\_mappings  
{ "properties": { "test": { "type": "keyword" } } }  
POST test/test/1  
{ "test": "1" }  
POST test/test/2  
{ "test": "2" }  
GET test/\_search?q=test:(1 OR 2)  
GET test/\_search?q=test:(1 2)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 17, 2018, 12:19pm UTC](https://discuss.elastic.co/t/keyword-type-cant-use-field-value1-value2-in-querystring/128279/8 "2018-04-17T12:19:42Z")

</div>

Try:

```
GET test/_search?q=test:1 test:2
```

---

<div class="post-metadata">

**Author:** ![laigood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/laigood/32/30060_2.png) [@laigood](https://discuss.elastic.co/u/laigood)\
**Post date:** [April 18, 2018, 1:53am UTC](https://discuss.elastic.co/t/keyword-type-cant-use-field-value1-value2-in-querystring/128279/9 "2018-04-18T01:53:49Z")

</div>

It's ok,But my code in 5.x is use by test:(1 2),I don't know why this can't be use in 6.x.

---

<div class="post-metadata">

**Author:** ![laigood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/laigood/32/30060_2.png) [@laigood](https://discuss.elastic.co/u/laigood)\
**Post date:** [April 18, 2018, 2:49am UTC](https://discuss.elastic.co/t/keyword-type-cant-use-field-value1-value2-in-querystring/128279/10 "2018-04-18T02:49:59Z")

</div>

I use profile to find the reason,in 6.x querysring "test:(1 2)" translate to "test:1 2",where 5.x translate to "test:1 test:2",is it a bug in 6.x querystring?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 18, 2018, 4:12am UTC](https://discuss.elastic.co/t/keyword-type-cant-use-field-value1-value2-in-querystring/128279/11 "2018-04-18T04:12:31Z")

</div>

@dakrone do you know?

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [April 18, 2018, 3:51pm UTC](https://discuss.elastic.co/t/keyword-type-cant-use-field-value1-value2-in-querystring/128279/12 "2018-04-18T15:51:02Z")

</div>

query\_string is using the analyzer for the field (in this case, the `test` field is a `keyword`, so the term is being analyzed as `"1 2"`, which doesn't exist.

If you need to analyze the query string differently, you can specify an analyzer, both of these work:

```auto
GET /test/_search?q=test:(1+2)&analyzer=whitespace

```

and

```auto
GET /test/_search
{
  "query": {
    "query_string": {
      "query": "(1 2)",
      "analyzer": "whitespace"
    }
  }
}

```

---

<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:** [May 16, 2018, 3:51pm UTC](https://discuss.elastic.co/t/keyword-type-cant-use-field-value1-value2-in-querystring/128279/13 "2018-05-16T15:51:36Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
