# Problems with getting/checking map value by given key in painless script

**URL:** <https://discuss.elastic.co/t/problems-with-getting-checking-map-value-by-given-key-in-painless-script/170901>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [March 5, 2019, 12:59pm UTC](https://discuss.elastic.co/t/problems-with-getting-checking-map-value-by-given-key-in-painless-script/170901 "2019-03-05T12:59:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olga\_Gorun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/olga_gorun/32/41560_2.png) [@Olga\_Gorun](https://discuss.elastic.co/u/Olga_Gorun)\
**Post date:** [March 5, 2019, 12:59pm UTC](https://discuss.elastic.co/t/problems-with-getting-checking-map-value-by-given-key-in-painless-script/170901/1 "2019-03-05T12:59:00Z")

</div>

I experience problems with getting/checking map value by given key in painless script.  
Examples:

```auto
GET tt/clip/_search
{
  "query": {
    "function_score": {
      "script_score": {
        "script": {
          "lang": "painless",
          "source": "def params_map=['title_tfidf':'title_tfidf','full_text_tfidf':'full_text_tfidf','ocr_tfidf':'text_tfidf','clips_ccs_tfidf':'text_tfidf','plot_tfidf':'text_tfidf'];Debug.explain(params_map['title_tfidf']);"
        }
      }
    }
  }
}

```

Results in

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "painless_class": "String",
        "to_string": "title_tfidf",
        "java_class": "java.lang.String",
        "script_stack": [
          "Debug.explain(params_map['title_tfidf']);",
          " ^---- HERE"
        ],
        "script": "def params_map=['title_tfidf':'title_tfidf','full_text_tfidf':'full_text_tfidf','ocr_tfidf':'text_tfidf','clips_ccs_tfidf':'text_tfidf','plot_tfidf':'text_tfidf'];Debug.explain(params_map['title_tfidf']);",
        "lang": "painless"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "tt_1.88",
        "node": "KB6gGqOMQwm3zMqUzBJW0w",
        "reason": {
          "type": "script_exception",
          "reason": "runtime error",
          "painless_class": "String",
          "to_string": "title_tfidf",
          "java_class": "java.lang.String",
          "script_stack": [
            "Debug.explain(params_map['title_tfidf']);",
            " ^---- HERE"
          ],
          "script": "def params_map=['title_tfidf':'title_tfidf','full_text_tfidf':'full_text_tfidf','ocr_tfidf':'text_tfidf','clips_ccs_tfidf':'text_tfidf','plot_tfidf':'text_tfidf'];Debug.explain(params_map['title_tfidf']);",
          "lang": "painless",
          "caused_by": {
            "type": "painless_explain_error",
            "reason": null
          }
        }
      }
    ]
  },
  "status": 500
}

```

The same result with

```auto
GET tt/clip/_search
{
  "query": {
    "function_score": {
      "script_score": {
        "script": {
          "lang": "painless",
          "source": "def params_map=['title_tfidf':'title_tfidf','full_text_tfidf':'full_text_tfidf','ocr_tfidf':'text_tfidf','clips_ccs_tfidf':'text_tfidf','plot_tfidf':'text_tfidf'];Debug.explain(params_map.get('title_tfidf'));"
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Olga\_Gorun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/olga_gorun/32/41560_2.png) [@Olga\_Gorun](https://discuss.elastic.co/u/Olga_Gorun)\
**Post date:** [March 5, 2019, 3:22pm UTC](https://discuss.elastic.co/t/problems-with-getting-checking-map-value-by-given-key-in-painless-script/170901/2 "2019-03-05T15:22:27Z")

</div>

Closing the question. The problem is found

---

<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:** [April 2, 2019, 3:22pm UTC](https://discuss.elastic.co/t/problems-with-getting-checking-map-value-by-given-key-in-painless-script/170901/3 "2019-04-02T15:22:28Z")

</div>

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