Obtain field names


(nmz) #1

Hi,

Is it possible to obtain the 'field names'[not values] of the indexed
document using java API in elastic search?


(David Pilato) #2

IMHO

You could get the mapping of your document type.
You can get your document as a Map and find field names as keys

Does it help ?

David :wink:
Twitter : @dadoonet / @elasticsearchfr

Le 2 mai 2012 à 11:11, nmz s.namitha.s@gmail.com a écrit :

Hi,

Is it possible to obtain the 'field names'[not values] of the indexed
document using java API in elastic search?


(nmz) #3

Hi,

Thanks for the reply.

I tried the following code:

ClusterState cs =
client.admin().cluster().prepareState().execute().actionGet().getState();
IndexMetaData imd = cs.getMetaData().index(INDEX_NAME);
MappingMetaData mmd = imd.mapping(DOCUMENT_NAME);
Map<String, Object> source = mmd.sourceAsMap();

source.keySet() -- only has the value 'properties'
source.values() -- has the remaining part of the document mapping.

So do I have to parse the values() and extract the 'field names' or is
there any other way to obtain the it.

Correct me if my approach is wrong.

On May 2, 2:17 pm, David Pilato da...@pilato.fr wrote:

IMHO

You could get the mapping of your document type.
You can get your document as a Map and find field names as keys

Does it help ?

David :wink:
Twitter : @dadoonet / @elasticsearchfr

Le 2 mai 2012 à 11:11, nmz s.namith...@gmail.com a écrit :

Hi,

Is it possible to obtain the 'field names'[not values] of the indexed
document using java API in elastic search?


(Shay Banon) #4

You will need to navigate through the map, or parse the source (using
jackson for example) in order to aggregate all the field names.

On Wed, May 2, 2012 at 1:45 PM, nmz s.namitha.s@gmail.com wrote:

Hi,

Thanks for the reply.

I tried the following code:

ClusterState cs =
client.admin().cluster().prepareState().execute().actionGet().getState();
IndexMetaData imd = cs.getMetaData().index(INDEX_NAME);
MappingMetaData mmd = imd.mapping(DOCUMENT_NAME);
Map<String, Object> source = mmd.sourceAsMap();

source.keySet() -- only has the value 'properties'
source.values() -- has the remaining part of the document mapping.

So do I have to parse the values() and extract the 'field names' or is
there any other way to obtain the it.

Correct me if my approach is wrong.

On May 2, 2:17 pm, David Pilato da...@pilato.fr wrote:

IMHO

You could get the mapping of your document type.
You can get your document as a Map and find field names as keys

Does it help ?

David :wink:
Twitter : @dadoonet / @elasticsearchfr

Le 2 mai 2012 à 11:11, nmz s.namith...@gmail.com a écrit :

Hi,

Is it possible to obtain the 'field names'[not values] of the indexed
document using java API in elastic search?


(system) #5