# "No field found for \["..."\] in mapping" error with correct mapping

**URL:** https://discuss.elastic.co/t/no-field-found-for-in-mapping-error-with-correct-mapping/270499
**Category:** Elasticsearch
**Tags:** painless
**Created:** [April 18, 2021, 3:34pm UTC](https://discuss.elastic.co/t/no-field-found-for-in-mapping-error-with-correct-mapping/270499 "2021-04-18T15:34:28Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Marco\_R](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_r/32/77348_2.png) [@Marco\_R](https://discuss.elastic.co/u/Marco_R)
#### Post date: [April 18, 2021, 3:34pm UTC](https://discuss.elastic.co/t/no-field-found-for-in-mapping-error-with-correct-mapping/270499/1 "2021-04-18T15:34:28Z")

</div>

Hello, new to elastic here.  
I am trying to run this:

```auto
GET /test/_search
{
  "query": {
    "match": {
      "doc_type": "test"
    }
  },
  "sort": {
    "_script" : {
      "type" : "number",
      "script" : {
          "lang": "painless",
          "source": "doc['price'].value + doc['price'].value"
      },
      "order" : "desc"
  }
  }
}

```

and I am getting this:

```auto
"type" : "script_exception",
          "reason" : "runtime error",
          "script_stack" : [
            "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:65)",
            "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:27)",
            "doc['price'].value + doc['price'].value",
            " ^---- HERE"
          ],
          "script" : "doc['price'].value + doc['price'].value",
          "lang" : "painless",
          "position" : {
            "offset" : 4,
            "start" : 0,
            "end" : 39
          },
          "caused_by" : {
            "type" : "illegal_argument_exception",
            "reason" : "No field found for [price] in mapping"
          }

```

this is part of the mapping (from \_mapping request)

```auto
{
  "test": {
    "mappings": {
      "properties": {
        "doc": {
          "properties": {
            "itemId": {
              "type": "long"
            },
            "price": {
              "type": "float"
            }
        },
        "doc_type": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  }
}

```

My mapping seems correct, for what I am trying to do.  
I have searched the internet and this forum for an answer, with no luck.  
I am sorry if what I am trying may seem useless, but it's only a learning test.  
I am using version 7.12

Thanks in advanced

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [April 18, 2021, 4:17pm UTC](https://discuss.elastic.co/t/no-field-found-for-in-mapping-error-with-correct-mapping/270499/2 "2021-04-18T16:17:48Z")

</div>

Accessing a value in painless is the format you are using. `doc['price'].value`

What might be confusing is you have a `doc` in your mapping with `price` nested in there and that doesn't have anything to do with the `doc` in `doc['price'].value`.

I would try `doc['doc.price'].value`

---

<div class="post-metadata">

### Author: ![Marco\_R](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_r/32/77348_2.png) [@Marco\_R](https://discuss.elastic.co/u/Marco_R)
#### Post date: [April 18, 2021, 4:31pm UTC](https://discuss.elastic.co/t/no-field-found-for-in-mapping-error-with-correct-mapping/270499/3 "2021-04-18T16:31:49Z")

</div>

you are absolutely right, obviously. thank you very much.  
I am going to re-read the painless documentation

---

<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, 2021, 4:31pm UTC](https://discuss.elastic.co/t/no-field-found-for-in-mapping-error-with-correct-mapping/270499/4 "2021-05-16T16:31:53Z")

</div>

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