Not able to search through attachment contents

No. I don't know C#.

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

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

You need to fix the mapping.

@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

What gives GET yourindex/_mapping?

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`

Please format your code using </> icon as explained in this guide. 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.

@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

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.

@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

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 it should work.

As you can see, the mapping is defined:

PUT /trying-out-mapper-attachments
{
  "mappings": {
    "person": {
      "properties": {
        "cv": { "type": "attachment" }
}}}}
@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"
			}
		}
	}
}