ElasticSearch의 클라이언트로 Tire gem을 사용하여 PDF 첨부 파일을 인덱싱하고 싶습니다.매핑되지 않은 필드는 ElasticSearch에서 반환 한 검색 결과에 포함됩니다.
mapping :_source => { :excludes => ['attachment_original'] } do
indexes :id, :type => 'integer'
indexes :folder_id, :type => 'integer'
indexes :attachment_file_name
indexes :attachment_updated_at, :type => 'date'
indexes :attachment_original, :type => 'attachment'
end
난 아직도 첨부 파일 내용이 검색에 포함 볼 수 있습니다 : 첨부 파일이 인덱스에 저장되지 않고 검색이 결과에 반환되지 않도록 내 매핑, 나는, _source에서 첨부 파일 필드를 제외 나는 다음과 같은 컬 명령을 실행할 때 결과 :
하지만 난 그냥뿐만 아니라 첨부 파일이 있음을 발견했습니다 :
curl -X POST "http://localhost:9200/user_files/user_file/_search?pretty=true" -d '{
"query": {
"query_string": {
"query": "rspec"
}
}
}'
나는이 thread에 내 질문을 게시 검색 결과에 포함,하지만 당신은 여기에서 볼 수있는 매핑되지 않은 사람을 포함하여 다른 모든 필드는 또한 포함되어 있습니다
{
"took": 20,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.025427073,
"hits": [
{
"_index": "user_files",
"_type": "user_file",
"_id": "5",
"_score": 0.025427073,
"_source": {
"user_file": {
"id": 5,
"folder_id": 1,
"updated_at": "2012-08-16T11:32:41Z",
"attachment_file_size": 179895,
"attachment_updated_at": "2012-08-16T11:32:41Z",
"attachment_file_name": "hw4.pdf",
"attachment_content_type": "application/pdf",
"created_at": "2012-08-16T11:32:41Z",
"attachment_original": "JVBERi0xLjQKJeLjz9MKNyA"
}
}
}
]
}
}
attachment_file_size
및 attachment_content_type
이 매핑에 정의되지 않은,하지만 반환됩니다 검색 결과 :
{
"id": 5,
"folder_id": 1,
"updated_at": "2012-08-16T11:32:41Z",
"attachment_file_size": 179895, <---------------------
"attachment_updated_at": "2012-08-16T11:32:41Z",
"attachment_file_name": "hw4.pdf", <------------------
"attachment_content_type": "application/pdf",
"created_at": "2012-08-16T11:32:41Z",
"attachment_original": "JVBERi0xLjQKJeLjz9MKNyA"
}
여기 내 전체 구현의 :
이
include Tire::Model::Search
include Tire::Model::Callbacks
def self.search(folder, params)
tire.search() do
query { string params[:query], default_operator: "AND"} if params[:query].present?
#filter :term, folder_id: folder.id
#highlight :attachment_original, :options => {:tag => "<em>"}
raise to_curl
end
end
mapping :_source => { :excludes => ['attachment_original'] } do
indexes :id, :type => 'integer'
indexes :folder_id, :type => 'integer'
indexes :attachment_file_name
indexes :attachment_updated_at, :type => 'date'
indexes :attachment_original, :type => 'attachment'
end
def to_indexed_json
to_json(:methods => [:attachment_original])
end
def attachment_original
if attachment_file_name.present?
path_to_original = attachment.path
Base64.encode64(open(path_to_original) { |f| f.read })
end
end
누군가가 나를 왜 모든 필드을 알아내는 데 도움이 수 _source
에 다시 포함 되나요?
편집 : 이것은 모든 필드가 매핑에 포함 된 몇 가지 이유로 볼 수 있듯이 localhost:9200/user_files/_mapping
{
"user_files": {
"user_file": {
"_source": {
"excludes": [
"attachment_original"
]
},
"properties": {
"attachment_content_type": {
"type": "string"
},
"attachment_file_name": {
"type": "string"
},
"attachment_file_size": {
"type": "long"
},
"attachment_original": {
"type": "attachment",
"path": "full",
"fields": {
"attachment_original": {
"type": "string"
},
"author": {
"type": "string"
},
"title": {
"type": "string"
},
"name": {
"type": "string"
},
"date": {
"type": "date",
"format": "dateOptionalTime"
},
"keywords": {
"type": "string"
},
"content_type": {
"type": "string"
}
}
},
"attachment_updated_at": {
"type": "date",
"format": "dateOptionalTime"
},
"created_at": {
"type": "date",
"format": "dateOptionalTime"
},
"folder_id": {
"type": "integer"
},
"id": {
"type": "integer"
},
"updated_at": {
"type": "date",
"format": "dateOptionalTime"
}
}
}
}
}
를 실행의 출력입니다!
이 스레드에서 http://stackoverflow.com/questions/11251851/how-do-you-index-attachment-in-elasticsearch-with-tire?rq=1 정의되지 않은 필드가 맵핑. –