1

Having a model class which is represtented like below,

class Search{

int id,
List<User> users;
}

class User{
int id,
String name;
}

For the mentioned class i would like to create mapping in elasticSearch and was wondering how to achieve the same.Googled everywhere but i couldn't get any, since i am very much new to elasticsearch.

I have pasted an incompleted index mapping below and requesting help to achieve the complete model mapping in elasticsearch.

PUT user_index
{
    "mappings": {
        "user_map": {
            "properties": {
                "id": {
                    "type": "integer"
                }
            }
        }
    }   
}
1

1 Answer 1

1

Make users a nested type and add the rest of the properties in there. Even, if you dont add properties of users, it would auto map them. Important thing is making users nested.

   PUT user_index
    {  
     "mappings":{  
      "users":{  
         "type":"nested",
         "properties":{  
            "id":{  
               "type":"integer"
            },
            "name":{  
               "type":"text",
               "fields":{  
                  "keyword":{  
                     "type":"keyword"
                  }
               }
            }
         }
      }
   }
}

Refer : Using nested fields for arrays of objects

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.