# Combine normal and nested fields with query\_string

**URL:** <https://discuss.elastic.co/t/combine-normal-and-nested-fields-with-query-string/315502>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [September 29, 2022, 8:54pm UTC](https://discuss.elastic.co/t/combine-normal-and-nested-fields-with-query-string/315502 "2022-09-29T20:54:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antonio\_Antovski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/antonio_antovski/32/65944_2.png) [@Antonio\_Antovski](https://discuss.elastic.co/u/Antonio_Antovski)\
**Post date:** [September 29, 2022, 8:54pm UTC](https://discuss.elastic.co/t/combine-normal-and-nested-fields-with-query-string/315502/1 "2022-09-29T20:54:18Z")

</div>

I have a document which contains both normal and nested fields. I'm trying to find all the documents that contain all the words from a regex query in any of the fields of interest. Since I'm using a regex query and trying to match on multiple fields, the `query_string` seems like the best option for my case, but however it isn't working as expected.

Let's say I have the following documents (where only the `tags` field is nested):

```auto
[
	{
		"name": "doc1",
		"type": "document",
		"color": "blue",
		"tags": [
			{
				"name": "tag1",
				"description": "test tag"
			},
			{
				"name": "tag2",
				"description": "test tag"
			}
		]
	},
	{
		"name": "doc2",
		"type": "document",
		"color": "lightblue",
		"tags": [
			{
				"name": "tag2",
				"description": "test tag"
			},
			{
				"name": "tag3",
				"description": "test tag"
			}
		]
	},
	{
		"name": "doc3",
		"type": "document",
		"color": "green",
		"tags": [
			{
				"name": "tag1",
				"description": "test tag"
			},
			{
				"name": "tag3",
				"description": "test tag"
			}
		]
	}
]

```

Now, I want to run something like:

```auto
{
	"query": {
		"bool": {
			"must": [
				{
					"query_string": {
						"query": "*doc* AND *blue* AND *tag2*",
						"fields": [
							"name^2",
							"color^1.5",
							"tags.name"
						]
					}
				}
			]
		}
	}
}

```

But this won't work, because the `query_string` is not nested.  
Splitting the query into 2 separate `query_string` queries (one for the normal and the other for the nested fields) won't work, because it will try to find all 3 words in the mentioned fields.  
Putting everything in a nested `query_string` also won't work because it can't access the normal fields.

Is there any possible solution to this? A possible solution (not the best) is to change the mapping of the `tags` field to be a normal object field instead of nested, but that could lead to other problems with different queries.

---

<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:** [October 27, 2022, 8:54pm UTC](https://discuss.elastic.co/t/combine-normal-and-nested-fields-with-query-string/315502/2 "2022-10-27T20:54:55Z")

</div>

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