# How to exclude attachment content and still searching inside it?

**URL:** <https://discuss.elastic.co/t/how-to-exclude-attachment-content-and-still-searching-inside-it/329191>\
**Category:** Elasticsearch\
**Created:** [April 3, 2023, 9:23am UTC](https://discuss.elastic.co/t/how-to-exclude-attachment-content-and-still-searching-inside-it/329191 "2023-04-03T09:23:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![aabdo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aabdo/32/118609_2.png) [@aabdo](https://discuss.elastic.co/u/aabdo)\
**Post date:** [April 3, 2023, 9:23am UTC](https://discuss.elastic.co/t/how-to-exclude-attachment-content-and-still-searching-inside-it/329191/1 "2023-04-03T09:23:13Z")

</div>

hello,  
to optimize my disk space, i'm excluding my attachment content in the mapping of my index. but i can't no longer search inside it . i don't know what am i messing !! . is there any solution for this issue ??

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 3, 2023, 9:50am UTC](https://discuss.elastic.co/t/how-to-exclude-attachment-content-and-still-searching-inside-it/329191/2 "2023-04-03T09:50:43Z")

</div>

Welcome!

Could you share exactly what you did?

---

<div class="post-metadata">

**Author:** ![aabdo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aabdo/32/118609_2.png) [@aabdo](https://discuss.elastic.co/u/aabdo)\
**Post date:** [April 3, 2023, 10:05am UTC](https://discuss.elastic.co/t/how-to-exclude-attachment-content-and-still-searching-inside-it/329191/3 "2023-04-03T10:05:56Z")

</div>

i'm using ingest pipeline to decode my base64 pdf file:

```auto

PUT _ingest/pipeline/attachment
{
  "description" : "Extract attachment information",
  "processors" : [
      {
        "attachment": {
          "field": "smart_content"
        }
      },
      {
        "remove": {
          "field": "smart_content"
        }
      }
  ]
}

```

and i'm using this mapping:

```auto
{
      "_source" : {
        "excludes" : [
          "smart_content",
          "attachment.content"
        ]
      },
      "properties" : {
        "attachment" : {
          "properties" : {
            "content" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "content_length" : {
              "type" : "long"
            },
            "content_type" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "date" : {
              "type" : "date"
            },
            "language" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "title" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
        "createdBy" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "createdDate" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "dateConservation" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "document" : {
          "properties" : {
            "comment" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "content" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "dateConservation" : {
              "type" : "date"
            },
            "dateNum" : {
              "type" : "date"
            },
            "dua" : {
              "type" : "long"
            },
            "idBundle" : {
              "type" : "long"
            },
            "idLot" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "metadata" : {
              "properties" : {
                "key" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                },
                "value" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                }
              }
            },
            "reference" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "scanProofAvailable" : {
              "type" : "boolean"
            },
            "status" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "tags" : {
              "properties" : {
                "color" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                },
                "key" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                }
              }
            },
            "unarchivable" : {
              "type" : "boolean"
            }
          }
        },
        "documentType" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "filename" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "forwardedBy" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "id" : {
          "type" : "date",
          "store" : true
        },
        "idCourier" : {
          "type" : "long"
        },
        "lastModifiedBy" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "lastModifiedDate" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "mailbox" : {
          "properties" : {
            "accesses" : {
              "properties" : {
                "type" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                },
                "user" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                }
              }
            },
            "id" : {
              "type" : "long"
            },
            "label" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "type" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
        "metadata" : {
          "properties" : {
            "key" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "value" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
        "smart_content" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "status" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 3, 2023, 11:45am UTC](https://discuss.elastic.co/t/how-to-exclude-attachment-content-and-still-searching-inside-it/329191/4 "2023-04-03T11:45:36Z")

</div>

What is the search request you are running?

---

<div class="post-metadata">

**Author:** ![aabdo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aabdo/32/118609_2.png) [@aabdo](https://discuss.elastic.co/u/aabdo)\
**Post date:** [April 3, 2023, 1:59pm UTC](https://discuss.elastic.co/t/how-to-exclude-attachment-content-and-still-searching-inside-it/329191/5 "2023-04-03T13:59:01Z")

</div>

i'm running a query\_string.

```auto
{
  "query": {
    "`query_string`": {
      "query": "something"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 3, 2023, 2:53pm UTC](https://discuss.elastic.co/t/how-to-exclude-attachment-content-and-still-searching-inside-it/329191/6 "2023-04-03T14:53:49Z")

</div>

Can you share a document that has been indexed which contains the word "something"?

For this, I'd change the mapping and remove the source exclusion on attachment.content.

I'm not sure why you wanted to remove it BTW.

Ideally, if you could reproduce the full problem with a very simple script, that'd help a lot to understand what you are doing wrong.

You could encode in BASE64 a minimal text file which contains the text you are then searching for.

---

<div class="post-metadata">

**Author:** ![aabdo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aabdo/32/118609_2.png) [@aabdo](https://discuss.elastic.co/u/aabdo)\
**Post date:** [April 3, 2023, 3:27pm UTC](https://discuss.elastic.co/t/how-to-exclude-attachment-content-and-still-searching-inside-it/329191/7 "2023-04-03T15:27:53Z")

</div>

to explain more my probleme:  
The first time i created my index without excluding the attachement.content, but a few mounths later, i find out that my index is taking a lot of space ( hundreds of GO ), because i'm indexing big PDF files . so i desided to look for a solution to remove atachment.content feild from my index without removing "\_termvectors" of this feild so a can keep the search fonctionality working.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 3, 2023, 5:35pm UTC](https://discuss.elastic.co/t/how-to-exclude-attachment-content-and-still-searching-inside-it/329191/8 "2023-04-03T17:35:58Z")

</div>

I don't think that removing the extracted text will improve a lot. But removing the binary content is indeed the way to go IMO.

---

<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:** [May 1, 2023, 5:36pm UTC](https://discuss.elastic.co/t/how-to-exclude-attachment-content-and-still-searching-inside-it/329191/9 "2023-05-01T17:36:24Z")

</div>

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