# Not able to search through attachment contents

**URL:** <https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473>\
**Category:** Elasticsearch\
**Created:** [October 19, 2015, 10:19am UTC](https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473 "2015-10-19T10:19:55Z")\
**Posts on this page:** 13\
**Page:** 2

<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:** [July 4, 2016, 2:10pm UTC](https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473/23 "2016-07-04T14:10:41Z")

</div>

No. I don't know C#.

---

<div class="post-metadata">

**Author:** ![rakesh-saharan](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@rakesh-saharan](https://discuss.elastic.co/u/rakesh-saharan)\
**Post date:** [December 29, 2016, 8:07am UTC](https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473/24 "2016-12-29T08:07:58Z")

</div>

Hi @dadoonet

I am trying to implement attachment mapper search using ruby and for file uploading on amazon s3, i am using paperclip.

My problem is similar i am not able to search through the document but i can search on other parameters like title or etc.

Mapping:

{  
"notes" : {  
"mappings" : {  
"note" : {  
"properties" : {  
"attachment" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
},  
"attachment\_content\_type" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
},  
"attachment\_data" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
},  
"attachment\_file\_name" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
},  
"attachment\_file\_size" : {  
"type" : "long"  
},  
"attachment\_updated\_at" : {  
"type" : "date"  
},  
"company\_id" : {  
"type" : "long"  
},  
"created\_at" : {  
"type" : "date"  
},  
"id" : {  
"type" : "long"  
},  
"member\_id" : {  
"type" : "long"  
},  
"note" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
},  
"noteable\_id" : {  
"type" : "long"  
},  
"noteable\_type" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
},  
"updated\_at" : {  
"type" : "date"  
},  
"visibility\_type" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
}  
}  
}  
}  
}  
}

And here is mapper code:

mapping \_source: { excludes: ["attachment"] } do  
self.tire.indexes :id, type: "integer"  
self.tire.indexes :note

```
self.tire.indexes :attachment, :type => 'attachment',
  :fields => {
    :name=> { :store => 'yes' },
    :content=> { :store => 'yes' },
    :title=> { :store => 'yes' },
    :file=> { :term_vector => 'with_positions_offsets', :store => 'yes' },
    :date=> { :store => 'yes' }

    }

```

end

def attachment\_data  
Base64.encode64(open(PATH\_TO\_ATTACHMENT) { |file| file.read })  
end

---

<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:** [December 29, 2016, 9:08am UTC](https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473/25 "2016-12-29T09:08:56Z")

</div>

But the mapping you showed doesn't contain a field of type "attachment".

You need to fix the mapping.

---

<div class="post-metadata">

**Author:** ![rakesh-saharan](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@rakesh-saharan](https://discuss.elastic.co/u/rakesh-saharan)\
**Post date:** [December 29, 2016, 11:21am UTC](https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473/26 "2016-12-29T11:21:54Z")

</div>

@dadoonet  
Here is the Mappingmapping \_source: { excludes: ["attachment"] } do  
self.tire.indexes :id, type: "integer"  
self.tire.indexes :note  
#self.tire.indexes :attachment, type: "attachment\_data"  
self.tire.indexes :attachment, :type =\> 'attachment',  
:fields =\> {  
:name=\> { :store =\> 'yes' },  
:content=\> { :store =\> 'yes' },  
:title=\> { :store =\> 'yes' },  
:file=\> { :term\_vector =\> 'with\_positions\_offsets', :store =\> 'yes' },  
:date=\> { :store =\> 'yes' }

```
    }

```

end

---

<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:** [December 29, 2016, 11:55am UTC](https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473/27 "2016-12-29T11:55:50Z")

</div>

What gives `GET yourindex/_mapping`?

---

<div class="post-metadata">

**Author:** ![rakesh-saharan](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@rakesh-saharan](https://discuss.elastic.co/u/rakesh-saharan)\
**Post date:** [December 29, 2016, 4:07pm UTC](https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473/28 "2016-12-29T16:07:36Z")

</div>

```
9200/notes/_mapping?pretty=true'
{
  "notes" : {
"mappings" : {
  "note" : {
    "properties" : {
      "attachment" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },
      "attachment_content_type" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },
      "attachment_data" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },
      "attachment_file_name" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },
      "attachment_file_size" : {
        "type" : "long"
      },
      "attachment_updated_at" : {
        "type" : "date"
      },
      "company_id" : {
        "type" : "long"
      },
      "created_at" : {
        "type" : "date"
      },
      "id" : {
        "type" : "long"
      },
      "member_id" : {
        "type" : "long"
      },
      "note" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },
      "noteable_id" : {
        "type" : "long"
      },
      "noteable_type" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },
      "updated_at" : {
        "type" : "date"
      },
      "visibility_type" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      }
    }
  }
}
  }
}`Preformatted text`
```

---

<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:** [December 29, 2016, 4:29pm UTC](https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473/29 "2016-12-29T16:29:20Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Can you see any `"type": "attachment"` in your mapping? I don't see any.  
That's your problem as I said before.

---

<div class="post-metadata">

**Author:** ![rakesh-saharan](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@rakesh-saharan](https://discuss.elastic.co/u/rakesh-saharan)\
**Post date:** [December 30, 2016, 12:55am UTC](https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473/30 "2016-12-30T00:55:00Z")

</div>

@dadoonet Right, Mapper attachment plugin is installed but attachment type is coming out is a text not an attachment not sure why , that where i am stuck

---

<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:** [December 30, 2016, 2:54am UTC](https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473/31 "2016-12-30T02:54:22Z")

</div>

Because you did not specify it.

I mean that you created a mapping at some point. But without the needed type.

Remove the index, put a correct mapping and start again your application.

---

<div class="post-metadata">

**Author:** ![rakesh-saharan](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@rakesh-saharan](https://discuss.elastic.co/u/rakesh-saharan)\
**Post date:** [December 30, 2016, 10:56am UTC](https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473/32 "2016-12-30T10:56:29Z")

</div>

```
@dadoonet I did specify it,Please see below

mapping _source: { excludes: ["attachment"] } do
self.tire.indexes :id, type: "integer"
self.tire.indexes :note
self.tire.indexes :attachment, :type => 'attachment',
:fields => {
:name=> { :store => 'yes' },
:content=> { :store => 'yes' },
:title=> { :store => 'yes' },
:file=> { :term_vector => 'with_positions_offsets', :store => 'yes' },
:date=> { :store => 'yes' }

}

```

I am following this [http://rny.io/rails/elasticsearch/2013/08/05/full-text-search-for-attachments-with-rails-and-elasticsearch.html](http://rny.io/rails/elasticsearch/2013/08/05/full-text-search-for-attachments-with-rails-and-elasticsearch.html)

---

<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:** [December 30, 2016, 10:59am UTC](https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473/33 "2016-12-30T10:59:02Z")

</div>

It's not in the mapping at the end. So you are probably doing something wrong.  
I can't tell as I don't know Rails/Ruby.

But if you follow the documentation and replay [this pure REST script](https://www.elastic.co/guide/en/elasticsearch/plugins/current/mapper-attachments-helloworld.html) it should work.

As you can see, the mapping is defined:

```auto
PUT /trying-out-mapper-attachments
{
  "mappings": {
    "person": {
      "properties": {
        "cv": { "type": "attachment" }
}}}}

```

---

<div class="post-metadata">

**Author:** ![rakesh-saharan](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@rakesh-saharan](https://discuss.elastic.co/u/rakesh-saharan)\
**Post date:** [January 3, 2017, 9:58am UTC](https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473/34 "2017-01-03T09:58:13Z")

</div>

```
@dadoonet This is what i am getting in json mapping, I have installed attachment plugin but still it shows attachmet_data type as text not sure why

 {
	"notes": {
		"aliases": {},
		"mappings": {
			"note": {
				"properties": {
					"attachment_content_type": {
						"type": "text",
						"fields": {
							"keyword": {
								"type": "keyword",
								"ignore_above": 256
							}
						}
					},
					"attachment_data": {
						"type": "text",
						"fields": {
							"keyword": {
								"type": "keyword",
								"ignore_above": 256
							}
						}
					},
					"attachment_file_name": {
						"type": "text",
						"fields": {
							"keyword": {
								"type": "keyword",
								"ignore_above": 256
							}
						}
					},
					"attachment_file_size": {
						"type": "long"
					},
					"attachment_updated_at": {
						"type": "date"
					},
					"company_id": {
						"type": "long"
					},
					"created_at": {
						"type": "date"
					},
					"id": {
						"type": "long"
					},
					"member_id": {
						"type": "long"
					},
					"note": {
						"type": "text",
						"fields": {
							"keyword": {
								"type": "keyword",
								"ignore_above": 256
							}
						}
					},
					"noteable_id": {
						"type": "long"
					},
					"noteable_type": {
						"type": "text",
						"fields": {
							"keyword": {
								"type": "keyword",
								"ignore_above": 256
							}
						}
					},
					"updated_at": {
						"type": "date"
					},
					"visibility_type": {
						"type": "text",
						"fields": {
							"keyword": {
								"type": "keyword",
								"ignore_above": 256
							}
						}
					}
				}
			}
		},
		"settings": {
			"index": {
				"creation_date": "1483437269500",
				"number_of_shards": "5",
				"number_of_replicas": "1",
				"uuid": "mXHekbRiRB2z9lmUYDDbJA",
				"version": {
					"created": "5000199"
				},
				"provided_name": "notes"
			}
		}
	}
}
```

---

<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 5, 2017, 10:04pm UTC](https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473/35 "2017-07-05T22:04:32Z")

</div>



[Previous page](https://discuss.elastic.co/t/not-able-to-search-through-attachment-contents/32473.md?page=1)
