I got stuck somewhere in the middle. Please help me out
I have an index "sanjay_info_idx", in which the sample record is given below.
{
"_index": "sanjay_info_idx",
"_type": "sanjay_info_idx",
"_id": "AVGmCwSaTP6SQFpi0uP0",
"_version": 1,
"_score": 1,
"_source": {
"contentLen": 1024,
"studentID": "163",
"admissionID": "55011",
"StudentName": "RASHI KHANNA",
"gender": "F",
"FacultyName": "SARIN",
"remarks": " Now we have the mappings, we can iterate the map to get the metadata. What we must be aware is that the structure is always the same whatever the specified parameters (index name, index type). This means that we need to browse the mapping structure in the same way. Following code describes how to get the mapping of types within a particular index ",
"suggestions": "This means that we need to browse the mapping structure in the same way. Following code describes how to get the mapping of types within a particular index mappings",
"theme": "What we must be aware is that the structure is always the same whatever the specified parameters mappings",
"subjects": {
"Maths": "yes",
"English": "yes",
"Social": "yes"
}
}
}
I have two things to achieve:
How to get all the field names in the index like ["_index","_type","_id","_version","_score","_source","contentLen","studentID","admissionID","StudentName","gender","FacultyName","remarks","suggestions","theme","subjects","Maths","English","Social"]
When I search for a string "mapping", I want to get all the field names where the search word mapping is found i.e, [remarks, suggestions, theme]. Is it possible. If yes, please guide me
But the problem is I'm getting all the fields except
"subjects": {
"Maths": "yes",
"English": "yes",
"Social": "yes"
}
Here I'm getting only subjects as field. But I want Maths, English , Social also as the field names. Is there anything that I have to change in the code???
In your example, you're not accessing the mapping per say, what you get is the _source of the returned hits. The source is a Map where the keys are Strings and the values are Objects, the key set you're getting is only the first level of field names in your search hit. The 'subjects' fields in your type is an object, this means that it's an inner map inside the source. If you want to access all the fields you'll need to check the values in the map as well and if the value is an instance of Map you'll have to check all the key/value inside it and so on. A recursive function should do the trick.
Is there any other possibility to get all the field names. Because the "subject" field may vary based on the student ID. So I need all the fields in the index. Can I get it using java code???
If yes, please guide me how to do it ...
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.