# Query terms with dash in string?

**URL:** <https://discuss.elastic.co/t/query-terms-with-dash-in-string/295780>\
**Category:** Elasticsearch\
**Created:** [January 30, 2022, 3:15pm UTC](https://discuss.elastic.co/t/query-terms-with-dash-in-string/295780 "2022-01-30T15:15:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emporea](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emporea/32/101071_2.png) [@Emporea](https://discuss.elastic.co/u/Emporea)\
**Post date:** [January 30, 2022, 3:15pm UTC](https://discuss.elastic.co/t/query-terms-with-dash-in-string/295780/1 "2022-01-30T15:15:53Z")

</div>

```auto
GET /_search
{
  "query": {
    "terms": {
      "user.id": ["kimchy", "elkbee-test"],
    }
  }
}

```

Result will only include kimchy, because I guess the dash is interpretet as a bool operator. How to fix this?

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [January 30, 2022, 3:50pm UTC](https://discuss.elastic.co/t/query-terms-with-dash-in-string/295780/2 "2022-01-30T15:50:09Z")

</div>

Hi @Emporea Welcome to the community.

That should work... it works for me, I do notice you have an extra `,` at the end of you `user.id` line

> [@Emporea](#):
>
> ` "user.id": ["kimchy", "elkbee-test"],` \<!-- Here extra comma

Here is my example

```auto
DELETE discuss-test

PUT discuss-test/
{
  "mappings": {
    "properties": {
      "name": {
        "type": "keyword"
      }
    }
  }
}

POST discuss-test/_doc
{
  "name" : "kimchy"
}

POST discuss-test/_doc
{
  "name" : "stephen-test"
}

POST discuss-test/_doc
{
  "name" : "john-test"
}

GET discuss-test/_search
{
  "query": {
    "terms": {
      "name": [
        "kimchy",
        "stephen-test"
      ]
    }
  }
}

```

and the results

```auto
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "discuss-test",
        "_type" : "_doc",
        "_id" : "F9Cpq34Bliuj9UVF3cyX",
        "_score" : 1.0,
        "_source" : {
          "name" : "kimchy"
        }
      },
      {
        "_index" : "discuss-test",
        "_type" : "_doc",
        "_id" : "GNCpq34Bliuj9UVF3cyp",
        "_score" : 1.0,
        "_source" : {
          "name" : "stephen-test"
        }
      }
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![Emporea](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emporea/32/101071_2.png) [@Emporea](https://discuss.elastic.co/u/Emporea)\
**Post date:** [January 30, 2022, 3:58pm UTC](https://discuss.elastic.co/t/query-terms-with-dash-in-string/295780/3 "2022-01-30T15:58:31Z")

</div>

Its not working for me. Hmm.

Edit:  
Its working.  
I know what I did wrong.. I didn't address the keyword field. Your answer / mappings made me realize tho!. Thanks!

=\> `field.keyword`

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [January 30, 2022, 4:01pm UTC](https://discuss.elastic.co/t/query-terms-with-dash-in-string/295780/4 "2022-01-30T16:01:38Z")

</div>

What version of Elasticsearch are you on?

If you run my code above what is the result? can you show me?

Do you have smart quotes on or something?

---

<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:** [February 27, 2022, 4:01pm UTC](https://discuss.elastic.co/t/query-terms-with-dash-in-string/295780/5 "2022-02-27T16:01:42Z")

</div>

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