# Storing path data in a field?

**URL:** <https://discuss.elastic.co/t/storing-path-data-in-a-field/89393>\
**Category:** Elasticsearch\
**Created:** [June 14, 2017, 2:15pm UTC](https://discuss.elastic.co/t/storing-path-data-in-a-field/89393 "2017-06-14T14:15:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![olexij](https://avatars.discourse-cdn.com/v4/letter/o/7993a0/32.png) [@olexij](https://discuss.elastic.co/u/olexij)\
**Post date:** [June 14, 2017, 2:15pm UTC](https://discuss.elastic.co/t/storing-path-data-in-a-field/89393/1 "2017-06-14T14:15:30Z")

</div>

I would like to store file path data in a document. The example document structure is  
{  
"hostname" : "socbm331",  
"path" : "/opt/sicl/bin/iproc",  
"type" : "f",  
"user" : "bin",  
"group" : "bin",  
"size" : 21871  
}

I would like to search the documents by path value.  
The search for

`http://localhost:9200/rspec_filesystem_snapshots/_search?q=path.keyword:%2Fopt%2Fsicl%2Fbin%2Fiproc&pretty`

gives me a load of documents with path value which do not match, like:  
`{ "hostname" : "socbm331", "path" : "/opt/sicl/share/man/man8/iproc.8", "type" : "f", "user" : "bin", "group" : "bin", "size" : 2077 }`

How to accomplish this with version 5.4 ?

---

<div class="post-metadata">

**Author:** ![CDR](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@CDR](https://discuss.elastic.co/u/CDR)\
**Post date:** [June 20, 2017, 6:35pm UTC](https://discuss.elastic.co/t/storing-path-data-in-a-field/89393/2 "2017-06-20T18:35:01Z")

</div>

Did you ever find a resolution for this? I would like to do this as well.

---

<div class="post-metadata">

**Author:** ![Olexij\_Tkatchenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/olexij_tkatchenko/32/9958_2.png) [@Olexij\_Tkatchenko](https://discuss.elastic.co/u/Olexij_Tkatchenko)\
**Post date:** [June 21, 2017, 6:13am UTC](https://discuss.elastic.co/t/storing-path-data-in-a-field/89393/3 "2017-06-21T06:13:27Z")

</div>

My current temporary workaround is to encode and store path\_base64 but it doesn't fix the problem.

---

<div class="post-metadata">

**Author:** ![CDR](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@CDR](https://discuss.elastic.co/u/CDR)\
**Post date:** [June 21, 2017, 12:10pm UTC](https://discuss.elastic.co/t/storing-path-data-in-a-field/89393/4 "2017-06-21T12:10:36Z")

</div>

Would you be able to show me the code about how to encode and store path\_base64?

---

<div class="post-metadata">

**Author:** ![olexij](https://avatars.discourse-cdn.com/v4/letter/o/7993a0/32.png) [@olexij](https://discuss.elastic.co/u/olexij)\
**Post date:** [June 21, 2017, 2:58pm UTC](https://discuss.elastic.co/t/storing-path-data-in-a-field/89393/5 "2017-06-21T14:58:54Z")

</div>

Sure, I'm retrieving data with ruby, here is a snippet of the transformation

```
def transform_entries_to_jdl(index_name = 'filesystem_snapshot_entries', marker = nil)

time = @timestamp
if @timestamp.class == 'String'
  time = Time.parse(@timestamp)
end

jdl = []
@entries.each do |entry|
  path = URI.escape(entry['path'])

  path_base64 = Base64.encode64(entry['path']).strip().gsub(/\n/, '')
  content = {:type => entry['type'], :user => entry['user'], :group => entry['group'], :size => entry['size'], :permissions => entry['permissions'], timestamp: time}
  value = {:hostname => hostname, :path => path, :path_base64 => path_base64, :type => entry['type'], :user => entry['user'], :group => entry['group'], :size => entry['size'], :permissions => entry['permissions'], timestamp: time, :configuration_checksum => Digest::MD5.hexdigest(content.to_s), :marker => marker}
  value_to_insert = {index: {_index: index_name, _type: 'filesystem_snapshot_entry', data: value}}
  jdl << value_to_insert
end

return jdl
end
```

---

<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 19, 2017, 2:59pm UTC](https://discuss.elastic.co/t/storing-path-data-in-a-field/89393/6 "2017-07-19T14:59:27Z")

</div>

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