# Keyword search not behaving as expected

**URL:** <https://discuss.elastic.co/t/keyword-search-not-behaving-as-expected/330328>\
**Category:** Elasticsearch\
**Created:** [April 19, 2023, 5:48pm UTC](https://discuss.elastic.co/t/keyword-search-not-behaving-as-expected/330328 "2023-04-19T17:48:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![developer3124](https://avatars.discourse-cdn.com/v4/letter/d/c0e974/32.png) [@developer3124](https://discuss.elastic.co/u/developer3124)\
**Post date:** [April 19, 2023, 5:48pm UTC](https://discuss.elastic.co/t/keyword-search-not-behaving-as-expected/330328/1 "2023-04-19T17:48:30Z")

</div>

Hello,

I'm having an issue with keyword search not behaving how I would expect from the docs. I can see that the following document exists in my index:

```auto
{
      "_index": "my-index",
      "_type": "_doc",
      "_id": "A-A1055-62",
      "_score": 9.326463,
      "_source": {
          "color": "AA105562",
          "description": "red"
      }
  }

```

But a keyword term query on my-index does not return any results:

```auto
{
    "size": 1,
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "color.keyword": {
                            "value": "AA105562",
                            "boost": 1.0
                        }
                    }
                }
            ],
            "adjust_pure_negative": true,
            "boost": 1.0
        }
    }
}

```

My mapping is set as:

```auto
"my-index": {
   "mappings": {
      "properties": {
          "color": {
              "type": "keyword"
          },
        }
    }
}

```

From the docs, I would have expected that a term query on color.keyword would find the document since the strings are identical. What am I missing?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 19, 2023, 6:04pm UTC](https://discuss.elastic.co/t/keyword-search-not-behaving-as-expected/330328/2 "2023-04-19T18:04:28Z")

</div>

You do not have a keyword multifield. Does this work?

```auto
{
    "size": 1,
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "color": {
                            "value": "AA105562",
                            "boost": 1.0
                        }
                    }
                }
            ],
            "adjust_pure_negative": true,
            "boost": 1.0
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![developer3124](https://avatars.discourse-cdn.com/v4/letter/d/c0e974/32.png) [@developer3124](https://discuss.elastic.co/u/developer3124)\
**Post date:** [April 19, 2023, 6:12pm UTC](https://discuss.elastic.co/t/keyword-search-not-behaving-as-expected/330328/3 "2023-04-19T18:12:33Z")

</div>

Yes it does - could you explain why that is? Or I'm not quite sure what is meant by a keyword multifield

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 19, 2023, 6:39pm UTC](https://discuss.elastic.co/t/keyword-search-not-behaving-as-expected/330328/4 "2023-04-19T18:39:09Z")

</div>

If you use [dynamic mapping](https://www.elastic.co/guide/en/elasticsearch/reference/8.7/dynamic-field-mapping.html) the default mapping is to map the field as `text` (analysed) and create a `keyword` sub field which is mapped as `keyword`. Since your field itself is mapped as a keyword you have no subfield defined so need to reference the field itself.

---

<div class="post-metadata">

**Author:** ![developer3124](https://avatars.discourse-cdn.com/v4/letter/d/c0e974/32.png) [@developer3124](https://discuss.elastic.co/u/developer3124)\
**Post date:** [April 19, 2023, 7:06pm UTC](https://discuss.elastic.co/t/keyword-search-not-behaving-as-expected/330328/5 "2023-04-19T19:06:52Z")

</div>

That makes sense - thank you so much!!

---

<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 17, 2023, 7:07pm UTC](https://discuss.elastic.co/t/keyword-search-not-behaving-as-expected/330328/6 "2023-05-17T19:07:42Z")

</div>

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