# "include\_in\_root" option with wildcard field causes "illegal\_argument\_exception"

**URL:** <https://discuss.elastic.co/t/include-in-root-option-with-wildcard-field-causes-illegal-argument-exception/290353>\
**Category:** Elasticsearch\
**Created:** [November 28, 2021, 6:49am UTC](https://discuss.elastic.co/t/include-in-root-option-with-wildcard-field-causes-illegal-argument-exception/290353 "2021-11-28T06:49:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [November 28, 2021, 6:49am UTC](https://discuss.elastic.co/t/include-in-root-option-with-wildcard-field-causes-illegal-argument-exception/290353/1 "2021-11-28T06:49:02Z")

</div>

Hello,  
I tried to use "include\_in\_root" option with nesting wildcard field but got error.

The Elasticsearch version is as follows:

```auto
"version" : {
    "number" : "7.15.2",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "93d5a7f6192e8a1a12e154a2b81bf6fa7309da0c",
    "build_date" : "2021-11-04T14:04:42.515624022Z",
    "build_snapshot" : false,
    "lucene_version" : "8.9.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"

```

First I created an index:

```auto
PUT test_nested_field
{
  "settings":{},
  "mappings":{
    "properties": {
      "parent_field": {
        "properties": {
          "nested_field": {
            "type": "nested",
            "include_in_root": true,
            "properties": {
              "wildcard_field": {
                "type": "wildcard"
              },
              "float_field": {
                "type": "float"
              },
              "integer_field": {
                "type": "integer"
              }
            }
          }
        }
      }
    }
  }
}

```

Then the following index was created successfully.

```auto
{
  "test_nested_field" : {
    "aliases" : { },
    "mappings" : {
      "properties" : {
        "parent_field" : {
          "properties" : {
            "nested_field" : {
              "type" : "nested",
              "include_in_root" : true,
              "properties" : {
                "float_field" : {
                  "type" : "float"
                },
                "integer_field" : {
                  "type" : "integer"
                },
                "wildcard_field" : {
                  "type" : "wildcard"
                }
              }
            }
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "routing" : {
          "allocation" : {
            "include" : {
              "_tier_preference" : "data_content"
            }
          }
        },
        "number_of_shards" : "1",
        "provided_name" : "test_nested_field",
        "creation_date" : "1638079974223",
        "number_of_replicas" : "1",
        "uuid" : "cypT5YzJTCOwOMLZnfM-ww",
        "version" : {
          "created" : "7150299"
        }
      }
    }
  }
}

```

But when I tried to index a document with the following query,

```auto
POST test_nested_field/_doc
{
  "parent_field": {
    "nested_field": [
      {
        "wildcard_field": "aaa",
        "integer_field": "14",
        "float_field": "0.52"
      },
      {
        "wildcard_field": "bbb",
        "integer_field": "1",
        "float_field": "0.04"
      }
    ]
  }
}

```

I got the following error:

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "DocValuesField \"parent_field.nested_field.wildcard_field\" appears more than once in this document (only one value is allowed per field)"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "DocValuesField \"parent_field.nested_field.wildcard_field\" appears more than once in this document (only one value is allowed per field)"
  },
  "status" : 400
}

```

Curiously the whole process went well

- with a single nesting object,
- without "include\_in\_root" option or
- without nesting wildcard field.

With a single nesting object:

```auto
POST test_nested_field/_doc
{
  "parent_field": {
    "nested_field": [
      {
        "wildcard_field": "aaa",
        "integer_field": "14",
        "float_field": "0.52"
      }
    ]
  }
}

{
  "_index" : "test_nested_field",
  "_type" : "_doc",
  "_id" : "VnVKZX0Bxutvf9KVhJFP",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "_seq_no" : 1,
  "_primary_term" : 1
}

```

Without "include\_in\_root" option:

```auto
PUT test_nested_field_without_include_in_root
{
  "settings":{},
  "mappings":{
    "properties": {
      "parent_field": {
        "properties": {
          "nested_field": {
            "type": "nested",
            "properties": {
              "wildcard_field": {
                "type": "wildcard"
              },
              "float_field": {
                "type": "float"
              },
              "integer_field": {
                "type": "integer"
              }
            }
          }
        }
      }
    }
  }
}

POST test_nested_field_without_include_in_root/_doc
{
  "parent_field": {
    "nested_field": [
      {
        "integer_field": "14",
        "float_field": "0.52"
      },
      {
        "integer_field": "1",
        "float_field": "0.04"
      }
    ]
  }
}

{
  "_index" : "test_nested_field_without_include_in_root",
  "_type" : "_doc",
  "_id" : "UnU8ZX0Bxutvf9KV-I_t",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "_seq_no" : 1,
  "_primary_term" : 1
}

```

Without nesting wildcard field:

```auto
PUT test_nested_field_without_wildcard
{
  "settings":{},
  "mappings":{
    "properties": {
      "parent_field": {
        "properties": {
          "nested_field": {
            "type": "nested",
            "include_in_root": true,
            "properties": {
              "float_field": {
                "type": "float"
              },
              "integer_field": {
                "type": "integer"
              }
            }
          }
        }
      }
    }
  }
}

POST test_nested_field_without_wildcard/_doc
{
  "parent_field": {
    "nested_field": [
      {
        "integer_field": "14",
        "float_field": "0.52"
      },
      {
        "integer_field": "1",
        "float_field": "0.04"
      }
    ]
  }
}

{
  "_index" : "test_nested_field_without_wildcard",
  "_type" : "_doc",
  "_id" : "N3U8ZX0Bxutvf9KVDY9n",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

```

I couldn't find any hint in [Nested field type](https://www.elastic.co/guide/en/elasticsearch/reference/7.15/nested.html) and [Wildcard field type](https://www.elastic.co/guide/en/elasticsearch/reference/7.15/keyword.html#wildcard-field-type).  
Is there something wrong in my query?

Thanks.

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [November 28, 2021, 6:56am UTC](https://discuss.elastic.co/t/include-in-root-option-with-wildcard-field-causes-illegal-argument-exception/290353/2 "2021-11-28T06:56:57Z")

</div>

I found a simmilar issue in Github.

> <https://github.com/elastic/elasticsearch/issues/12056>
>
> If you create a \`nested\` \`geo\_\*\` type and you attempt to use both \`include\_in\_pa…rent\` and \`doc\_values\`, then you cannot index multiple values. If you remove either setting, then it works.
> 
> \`\`\`
> PUT /test
> {
> "mappings": {
> "type": {
> "properties": {
> "location": {
> "type": "nested",
> "include\_in\_parent": true, 
> "properties": {
> "point": {
> "type": "geo\_point",
> "doc\_values": true
> }
> }
> }
> }
> }
> }
> }
> 
> \# Works
> PUT /test/type/1
> {
> "location" : {
> "point" : \[0, 0\]
> }
> }
> 
> \# Fails
> PUT /test/type/2
> {
> "location" : \[
> {
> "point" : \[0, 0\]
> },
> {
> "point" : \[1, 1\]
> }
> \]
> }
> \`\`\`
> 
> The first attempt works as expected, but the second attempt fails with an odd exception.
> 
> \`\`\` json
> {
> "error": "IllegalArgumentException\[DocValuesField \\"location.point\\" appears more than once in this document (only one value is allowed per field)\]",
> "status": 500
> }
> \`\`\`
> 
> This is related to https://github.com/elastic/elasticsearch/issues/10653#issuecomment-94097576, which notes that \`include\_in\_parent\` is ignored for \`geo\_\*\` types, but it does not suggest that it will fail upon trying to make use of it. This behavior should probably be explicitly blocked. Note: changing \`geo\_point\` to some type that does work with \`include\_in\_parent\`, such as \`long\`, does work.

I'm sorry if my case is the same as the issue.

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [November 29, 2021, 6:11am UTC](https://discuss.elastic.co/t/include-in-root-option-with-wildcard-field-causes-illegal-argument-exception/290353/3 "2021-11-29T06:11:43Z")

</div>

I came up with a workaround by myself.  
It is possible to use "copy\_to" option to achieve similar effect.  
I write it here to someone who will has the same problem.

```auto
PUT test_nested_field
{
  "settings":{},
  "mappings":{
    "properties": {
      "parent_field": {
        "properties": {
          "nested_field": {
            "type": "nested",
            "properties": {
              "wildcard_field": {
                "type": "wildcard",
                "copy_to": "wildcard_field"
              },
              "float_field": {
                "type": "float"
              },
              "integer_field": {
                "type": "integer"
              }
            }
          }
        }
      },
      "wildcard_field":{
        "type": "wildcard"
      }
    }
  }
}

POST test_nested_field/_doc
{
  "parent_field": {
    "nested_field": [
      {
        "wildcard_field": "aaa",
        "integer_field": "14",
        "float_field": "0.52"
      },
      {
        "wildcard_field": "ccc",
        "integer_field": "1",
        "float_field": "0.04"
      }
    ]
  }
}

GET test_nested_field/_search
{
  "query": {
    "wildcard": {
      "wildcard_field":"aa*"
    }
  }
}

```

Please close the topic.  
Thanks!

---

<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 27, 2021, 6:12am UTC](https://discuss.elastic.co/t/include-in-root-option-with-wildcard-field-causes-illegal-argument-exception/290353/4 "2021-12-27T06:12:05Z")

</div>

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