# Exclude certain fields from free text search - Elasticsearch

**URL:** https://discuss.elastic.co/t/exclude-certain-fields-from-free-text-search-elasticsearch/153010
**Category:** Elasticsearch
**Created:** [October 18, 2018, 1:39pm UTC](https://discuss.elastic.co/t/exclude-certain-fields-from-free-text-search-elasticsearch/153010 "2018-10-18T13:39:17Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)
#### Post date: [October 18, 2018, 1:39pm UTC](https://discuss.elastic.co/t/exclude-certain-fields-from-free-text-search-elasticsearch/153010/1 "2018-10-18T13:39:17Z")

</div>

Hi all,  
I have indexed documents with each over 100 field each analysed using Edge gram tokenizer to support Auto-Suggestion. I do require free text search that searches on all fields. When i am trying to do so, search is also happening fields with auto complete analyzed(ex. Data.autocomplete\_analyzed). I have to restrict this by searching only fields analysed with type "text"(ex. Data). Is there a method to do so in 1. Index time 2. Query time.  
Mapping file:

```
    "mappings": {
                "_doc": {
                    "properties": {
                        "Data": {
                            "type": "text",
                            "fields": {
                                "autocomplete_analyzed": {
                                    "type": "text",
                                    "analyzer": "autocomplete"
                                },
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        }
                } 
               }

```

Search query :

```
 {
"query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "aim",
            "type": "phrase",
            "slop": "2",
            "fields": []
          }
        },
        {
          "multi_match": {
            "query": "aim",
            "fuzziness": "1",
            "fields": []
          }
        }
      ],
      "minimum_should_match": 1 
}
```

---

<div class="post-metadata">

### Author: ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)
#### Post date: [October 23, 2018, 6:35am UTC](https://discuss.elastic.co/t/exclude-certain-fields-from-free-text-search-elasticsearch/153010/2 "2018-10-23T06:35:24Z")

</div>

@elastic can you please answer my query?

---

<div class="post-metadata">

### Author: ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)
#### Post date: [October 23, 2018, 10:34am UTC](https://discuss.elastic.co/t/exclude-certain-fields-from-free-text-search-elasticsearch/153010/3 "2018-10-23T10:34:25Z")

</div>

You could create a specific mapping with the default analyzer, then search on this field version.

```
PUT index
{
  "mappings": {
    "_doc": {
      "properties": {
        "Data": {
          "type": "text",
          "fields": {
            "default": {
              "type": "text",
              "analyzer": "standard"
            },
            "autocomplete_analyzed": {
              "type": "text",
              "analyzer": "autocomplete"
            },
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  }
}

```

And your query would be :

```
GET /index/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "aim",
            "type": "phrase",
            "slop": "2",
            "fields": [
              "*.default"
            ]
          }
        },
        {
          "multi_match": {
            "query": "aim",
            "fuzziness": "1",
            "fields": [
              "*.default"
            ]
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}
```

---

<div class="post-metadata">

### Author: ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)
#### Post date: [October 23, 2018, 12:17pm UTC](https://discuss.elastic.co/t/exclude-certain-fields-from-free-text-search-elasticsearch/153010/4 "2018-10-23T12:17:08Z")

</div>

@klof Thanks for your answer and time.  
This is one way to solve my issue, but I have around millions of documents with over 100 fields indexed. Indexing this way will increase storage consumption. Is there any other method to avoid this duplicacy ? Or is there any way to avoid certain fields in query time?

---

<div class="post-metadata">

### Author: ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)
#### Post date: [October 23, 2018, 1:07pm UTC](https://discuss.elastic.co/t/exclude-certain-fields-from-free-text-search-elasticsearch/153010/5 "2018-10-23T13:07:16Z")

</div>

I think it's fine, to have this new field version. But if you really want to optimize the mapping, you can set the main field as keyword and have only 2 other field versions.

```
PUT index
{
  "mappings": {
    "_doc": {
      "properties": {
        "Data": {
          "type": "keyword",
          "ignore_above": 256,
          "fields": {
            "default": {
              "type": "text",
              "analyzer": "standard"
            },
            "autocomplete_analyzed": {
              "type": "text",
              "analyzer": "autocomplete"
            }
          }
        }
      }
    }
  }
}

```

From what I know, I don't think it's possible to "deselect" fields at query time.

---

<div class="post-metadata">

### Author: ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)
#### Post date: [October 24, 2018, 7:08am UTC](https://discuss.elastic.co/t/exclude-certain-fields-from-free-text-search-elasticsearch/153010/6 "2018-10-24T07:08:45Z")

</div>

Thanks for your response  
Is there a method to mention a set of fields to be ignored for search at the index time?

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [November 1, 2018, 6:49am UTC](https://discuss.elastic.co/t/exclude-certain-fields-from-free-text-search-elasticsearch/153010/7 "2018-11-01T06:49:41Z")

</div>

A post was split to a new topic: [Problems with Elasticsearch after new download](https://discuss.elastic.co/t/problems-with-elasticsearch-after-new-download/154968)

---

<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: [November 29, 2018, 6:49am UTC](https://discuss.elastic.co/t/exclude-certain-fields-from-free-text-search-elasticsearch/153010/8 "2018-11-29T06:49:56Z")

</div>

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