# Elasticsearch 6.0 and joining queries

**URL:** <https://discuss.elastic.co/t/elasticsearch-6-0-and-joining-queries/109353>\
**Category:** Elasticsearch\
**Created:** [November 28, 2017, 9:38am UTC](https://discuss.elastic.co/t/elasticsearch-6-0-and-joining-queries/109353 "2017-11-28T09:38:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielburchardt](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@danielburchardt](https://discuss.elastic.co/u/danielburchardt)\
**Post date:** [November 28, 2017, 9:38am UTC](https://discuss.elastic.co/t/elasticsearch-6-0-and-joining-queries/109353/1 "2017-11-28T09:38:31Z")

</div>

Hello,

I trying create relation parent-child as in docs ([https://www.elastic.co/guide/en/elasticsearch/reference/current/parent-join.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/parent-join.html)) but when i querying:

```
{
  "query": {
    "parent_id": { 
      "type": "answer",
      "id": "1"
    }
  },
  "aggs": {
    "parents": {
      "terms": {
        "field": "my_join_field#question", 
        "size": 10
      }
    }
  },
  "script_fields": {
    "parent": {
      "script": {
         "source": "doc['my_join_field#question']" 
      }
    }
  }
}

```

I got error:

```
{
  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "compile error",
        "script_stack" : [
          "doc[my_join_field#question]",
          " ^---- HERE"
        ],
        "script" : "doc[my_join_field#question]",
        "lang" : "painless"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "my_index",
        "node" : "s4udXhJ0QJu6D5s7LhHnCA",
        "reason" : {
          "type" : "script_exception",
          "reason" : "compile error",
          "script_stack" : [
            "doc[my_join_field#question]",
            " ^---- HERE"
          ],
          "script" : "doc[my_join_field#question]",
          "lang" : "painless",
          "caused_by" : {
            "type" : "illegal_argument_exception",
            "reason" : "unexpected character [#].",
            "caused_by" : {
              "type" : "lexer_no_viable_alt_exception",
              "reason" : null
            }
          }
        }
      }
    ]
  },
  "status" : 500
}

```

What i'm doing wrong?

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [December 1, 2017, 9:34am UTC](https://discuss.elastic.co/t/elasticsearch-6-0-and-joining-queries/109353/2 "2017-12-01T09:34:12Z")

</div>

I am not able to reproduce the issue. I tried with the mapping and documents provided in the docs and it worked fine. Can you post the full list of actions that you did to encounter this exception ?

---

<div class="post-metadata">

**Author:** ![danielburchardt](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@danielburchardt](https://discuss.elastic.co/u/danielburchardt)\
**Post date:** [December 1, 2017, 10:04am UTC](https://discuss.elastic.co/t/elasticsearch-6-0-and-joining-queries/109353/3 "2017-12-01T10:04:58Z")

</div>

Elasticsearch info

```
curl -XGET 'http://localhost:9200/?pretty'
{
  "name" : "s4udXhJ",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "wOJP0hvERu2G6bUZAPqKcQ",
  "version" : {
    "number" : "6.0.0",
    "build_hash" : "8f0685b",
    "build_date" : "2017-11-10T18:41:22.859Z",
    "build_snapshot" : false,
    "lucene_version" : "7.0.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

```

Index

```
curl -XPUT 'http://localhost:9200/test_index' -H "Content-Type: application/json" -d '{
"settings" : {
  "analysis" : {
    "char_filter" : {
        "space_hashtags" : {
            "type" : "mapping",
            "mappings" : ["#=>|#"]
        }
    },
    "filter" : {
        "hashtag_as_alphanum" : {
            "type" : "standard",
            "type_table": ["# => ALPHANUM", "@ => ALPHANUM"]
        }
    },
    "analyzer" : {
        "hashtag" : {
            "type" : "custom",
            "tokenizer" : "whitespace",
            "filter" : ["lowercase", "hashtag_as_alphanum"]
        }
    }
}
},
"mappings" : {
"item" : {
    "properties" : {
        "text" : { "type" : "text", "analyzer": "hashtag" },
			"type": {"type": "join", "relations": {"user": "post"}}
    }
}
}
}'

```

Items

```
curl -XPUT 'http://localhost:9200/test_index/item/1?pretty' -H 'Content-Type: application/json' -d '
{
  "text": "daniel",
  "type": "user"
}'

curl -XPUT 'http://localhost:9200/test_index/item/2?pretty' -H 'Content-Type: application/json' -d '
{
  "text": "marta",
  "type": "user" 
}'

curl -XPUT 'http://localhost:9200/test_index/item/3?routing=1&pretty' -H 'Content-Type: application/json' -d '
{
  "text": "post1",
  "type": {"name": "post", "parent": 1} 
}'

curl -XPUT 'http://localhost:9200/test_index/item/4?routing=1&pretty' -H 'Content-Type: application/json' -d '
{
  "text": "post2",
  "type": {"name": "post", "parent": 1} 
}'

curl -XPUT 'http://localhost:9200/test_index/item/5?routing=1&pretty' -H 'Content-Type: application/json' -d '
{
  "text": "post3",
  "type": {"name": "post", "parent": 2} 
}'

curl -XPUT 'http://localhost:9200/test_index/item/6?routing=1&pretty' -H 'Content-Type: application/json' -d '
{
  "text": "post4",
  "type": {"name": "post", "parent": 2} 
}'

curl -XPUT 'http://localhost:9200/test_index/item/7?routing=1&pretty' -H 'Content-Type: application/json' -d '
{
  "text": "post5",
  "type": {"name": "post", "parent": 2} 
}'

```

Query

```
curl -XGET 'http://localhost:9200/test_index/_search' -H 'Content-Type: application/json' -d '
{
  "query": {
    "parent_id": { 
      "type": "post"
    }
  },
  "aggs": {
    "parents": {
      "terms": {
        "field": "type#user", 
        "size": 10
      }
    }
  },
  "script_fields": {
    "parent": {
      "script": {
         "source": "doc['type#user']" 
      }
    }
  }
}'

```

Result

```
{
  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "compile error",
        "script_stack" : [
          "doc[type#user]",
          " ^---- HERE"
        ],
        "script" : "doc[type#user]",
        "lang" : "painless"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "test_index",
        "node" : "s4udXhJ0QJu6D5s7LhHnCA",
        "reason" : {
          "type" : "script_exception",
          "reason" : "compile error",
          "script_stack" : [
            "doc[type#user]",
            " ^---- HERE"
          ],
          "script" : "doc[type#user]",
          "lang" : "painless",
          "caused_by" : {
            "type" : "illegal_argument_exception",
            "reason" : "unexpected character [#].",
            "caused_by" : {
              "type" : "lexer_no_viable_alt_exception",
              "reason" : null
            }
          }
        }
      }
    ]
  },
  "status" : 500
}
```

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [December 1, 2017, 10:44am UTC](https://discuss.elastic.co/t/elasticsearch-6-0-and-joining-queries/109353/4 "2017-12-01T10:44:10Z")

</div>

If you use curl you need to encode the single quote. "'" is not defined in the json spec so you have to replace `'` with the unicode point `\u0027`:

```auto
doc[\u0027type#user\u0027]

```

Note that the conversion is done automatically when you use the `COPY AS CURL` button in the documentation.

---

<div class="post-metadata">

**Author:** ![danielburchardt](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@danielburchardt](https://discuss.elastic.co/u/danielburchardt)\
**Post date:** [December 1, 2017, 10:59am UTC](https://discuss.elastic.co/t/elasticsearch-6-0-and-joining-queries/109353/5 "2017-12-01T10:59:52Z")

</div>

You are right! Thank you for help!

---

<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:** [December 29, 2017, 11:00am UTC](https://discuss.elastic.co/t/elasticsearch-6-0-and-joining-queries/109353/6 "2017-12-29T11:00:08Z")

</div>

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