# Query configuration returns to many hits

**URL:** <https://discuss.elastic.co/t/query-configuration-returns-to-many-hits/275325>\
**Category:** Elasticsearch\
**Created:** [June 8, 2021, 4:53pm UTC](https://discuss.elastic.co/t/query-configuration-returns-to-many-hits/275325 "2021-06-08T16:53:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rammi22](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@Rammi22](https://discuss.elastic.co/u/Rammi22)\
**Post date:** [June 8, 2021, 4:53pm UTC](https://discuss.elastic.co/t/query-configuration-returns-to-many-hits/275325/1 "2021-06-08T16:53:30Z")

</div>

Hi,

i have 1000 index-documents with following structure:

```auto
// #1
{
	"_index": "my_index_2008",
	"_type": "_doc",
	"_version": 1,
	"_seq_no": 1,
	"_primary_term": 1,
	"found": true,
	"_source": {
		"meta": {
			...
		},
		"data": {
			"main": {
				"behavior": "prototype"
				"refType": 1,
				...
			},
			"detail": {
				"auth": "123abc456",
				"ip": "xxx",
				"clientPhoneNumber": "123456789",
				"userparam": "Professional"
			}
		}
	}
}
// #2
{
	"_index": "my_index_2008",
	"_type": "_doc",
	"_version": 1,
	"_seq_no": 1,
	"_primary_term": 1,
	"found": true,
	"_source": {
		"meta": {
			...
		},
		"data": {
			"main": {
				"behavior": "any_string",
				...
				"refType": 3,
				...
			},
			"detail": {
				"auth": "555rock",
				"userparam": "Pro-Account",
                               "address": "road to nowhere"
			}
		}
	}
}
...

```

The goal of the search is to find any record, where the value of defined fields `data.detail.*` match a wildcard string: `*ro*`. But only if record field `data.main.refType` IN (1,2,3).

In sql-language like this:

```auto
SELECT * FROM my_index_2008 
WHERE  
(
    data.main.behavior LIKE 'ro' 
   OR 
    data.detail.userparam LIKE 'ro' 
   OR 
    data.detail.auth LIKE 'ro' 
   OR 
   data.detail.address LIKE 'ro'
)
  AND
(
  data.main.refType = 1
  OR
  data.,main.refType = 2
)

```

So my _first_ test-query looks like this:

```auto
{
	"explain": true,
	"query": {
		"bool": {
			"should": [
				{
					"wildcard": {
						"data.mainl.behavior": "*ro*"
					}
				},
				{
					"wildcard": {
						"data.detail.userparam": "*ro*"
					}
				},
				{
					"wildcard": {
						"data.detail.auth": "*ro*"
					}
				},
				{
					"wildcard": {
						"data.detail.address": "*ro*"
					}
				},
			]
		}
	},
	"size": 1000,
	"from": 0,
	"sort": []
}

```

Ok, fine, return number of hits (22) as expected.

But how to add the cluster for the `refType`?

```auto
{
   explain": true,
	"query": {
		"bool": {
			"should": [
				...,
                {
				    "match": {
				        "data.main.refType": 1
				    }
				},
                {
				    "match": {
				        "data.main.refType": 2
				    }
			]
		}
	},
	"size": 1000,
	"from": 0,
	"sort": []
}

```

... returned more hits than expected (total 734)

**How** to configurate the query, to make it work?

Greets

---

<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:** [July 6, 2021, 4:54pm UTC](https://discuss.elastic.co/t/query-configuration-returns-to-many-hits/275325/2 "2021-07-06T16:54:30Z")

</div>

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