# How to don't search for specific fields on Elasticsearch 6.1

**URL:** <https://discuss.elastic.co/t/how-to-dont-search-for-specific-fields-on-elasticsearch-6-1/112712>\
**Category:** Elasticsearch\
**Created:** [December 20, 2017, 8:17pm UTC](https://discuss.elastic.co/t/how-to-dont-search-for-specific-fields-on-elasticsearch-6-1/112712 "2017-12-20T20:17:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lfernandes](https://avatars.discourse-cdn.com/v4/letter/l/b2d939/32.png) [@lfernandes](https://discuss.elastic.co/u/lfernandes)\
**Post date:** [December 20, 2017, 8:17pm UTC](https://discuss.elastic.co/t/how-to-dont-search-for-specific-fields-on-elasticsearch-6-1/112712/1 "2017-12-20T20:17:55Z")

</div>

To do mapping on Elasticsearch 5.x I use `_all enabled => true` and for each field which I **don't** want to look for, I set `include_in_all => false`. I.e.:

```
'_all' => array(
	'enabled' => false
),
'properties' => array(
	'relevant_search_field' => array(
		'type' => 'text',
	),
	'value_needed_but_not_searchable' => array(
		'type' => 'text',
		'include_in_all'=> false
	)
)

```

Now, on Elasticsearch 6.1 `_all` is not recommended and `include_in_all` disallowed, so how can I set the fields which I want (or don't want) look for in the search ?

PS: I understand the reason `_all` is being removed due disk space and other things, and in fact, I don't want to use `copy_to` too, I just want set the fields to perform the search.

_References_  
[Why \_all is not good idea](https://github.com/elastic/elasticsearch/issues/19784)  
[Why \_all is not good idea ²](https://github.com/elastic/elasticsearch/issues/22923)  
[Deprecated on ES 6.x](https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking_60_mappings_changes.html)  
[From where I got the idea to use include\_in\_all for what I need](https://github.com/elastic/elasticsearch/issues/13516)

---

<div class="post-metadata">

**Author:** ![shanec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shanec/32/4004_2.png) [@shanec](https://discuss.elastic.co/u/shanec)\
**Post date:** [December 23, 2017, 1:17am UTC](https://discuss.elastic.co/t/how-to-dont-search-for-specific-fields-on-elasticsearch-6-1/112712/2 "2017-12-23T01:17:16Z")

</div>

You have a few options. It sounds like you've already looked into one of them.

1. You can set `index.query.default_field` on the index, which is the closest to the "old behavior" you had: [https://www.elastic.co/guide/en/elasticsearch/reference/6.1/query-dsl-query-string-query.html#\_default\_field](https://www.elastic.co/guide/en/elasticsearch/reference/6.1/query-dsl-query-string-query.html#_default_field)
2. You can pass in the fields as part of your search as you can see on [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html)
3. You can use `copy_to` as you've seen

1 is probably going to be the easiest, though if you have control over the application that's querying Elasticsearch, you could specify a more exact set of fields at query time which may be better if you don't want to define the same defaults for any app using the index.

---

<div class="post-metadata">

**Author:** ![lfernandes](https://avatars.discourse-cdn.com/v4/letter/l/b2d939/32.png) [@lfernandes](https://discuss.elastic.co/u/lfernandes)\
**Post date:** [December 26, 2017, 7:12pm UTC](https://discuss.elastic.co/t/how-to-dont-search-for-specific-fields-on-elasticsearch-6-1/112712/3 "2017-12-26T19:12:35Z")

</div>

Hello Shane,

The first option seems to be exacly what i was looking for. But how can I define multiple fields on it ? I tried:

```auto
"mappings": {
  "my_type": {
    "properties": {
      "relevant_search_field_1": {
        "type": "text"
      },
      "relevant_search_field_2": {
        "type": "text"
      }
    }
  }
},
"settings": {
  "index.query.default_field": "relevant_search_field_1, relevant_search_field_2" 
}

```

and

```auto
"settings": {
  "index.query.default_field": [{
  "relevant_search_field_1"
  },
  {
    "relevant_search_field_2"
  }]
}

```

But those fields are not searchable (seems to not work).

How can I set more than one field to `index.query.default_field` ?

PS: Some fields I have the same name or more than one type (i.e.: `my_type` and `my_type_2` have the same property `name`). So, to define may I should specify the object type as well (I.e.: `my_type`.`name`) ?

---

<div class="post-metadata">

**Author:** ![shanec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shanec/32/4004_2.png) [@shanec](https://discuss.elastic.co/u/shanec)\
**Post date:** [December 26, 2017, 8:04pm UTC](https://discuss.elastic.co/t/how-to-dont-search-for-specific-fields-on-elasticsearch-6-1/112712/4 "2017-12-26T20:04:01Z")

</div>

You just need an array of fieldnames there. Here's a short POC showing how to configure it / how it works:

```auto
PUT t
{
  "settings": {
    "index.query.default_field": ["relevant_search_field_1","relevant_search_field_2"]
  },
  "mappings": {
    "my_type": {
      "properties": {
        "relevant_search_field_1": {
        "type": "text"
        },
        "relevant_search_field_2": {
          "type": "text"
        },
        "irrelevant_search_field_1": {
          "type": "text"
        },
        "irrelevant_search_field_2": {
          "type": "text"
        }
      }
    }
  }
}

POST /t/my_type
{
  "relevant_search_field_1": "quick",
  "relevant_search_field_2": "brown",
  "irrelevant_search_field_1": "fox",
  "irrelevant_search_field_2": "jumped"
}

```

Now if you do `GET /t/my_type/_search?q=quick` or `GET /t/my_type/_search?q=brown` you'll get the hit and if you do `GET /t/my_type/_search?q=fox` or `GET /t/my_type/_search?q=jumped` you'll get 0 hits.

---

<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:** [January 23, 2018, 8:04pm UTC](https://discuss.elastic.co/t/how-to-dont-search-for-specific-fields-on-elasticsearch-6-1/112712/5 "2018-01-23T20:04:48Z")

</div>

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