0

I want to know how to get only the properties inside the mapping from using react frontend. this mappings is in my backend. I want to get only the properties not the value using elastic search query .backend is nodejs one . Output should be the account, class, team_members.id, team_members.name, team_members.priority .

  "mappings": {
            "properties": {
                "account": {"type": "integer"},
                  "class" : { "type" : "keyword",
                            "normalizer" : "my_normalizer"
                          },
                "team_members": {
                    "properties": {
                        "id": {"type": "integer"},
                        "name": {"type": "text"},
                        "priority": {"type": "integer"}
                    }
               }
          }
    }
Oshini
  • 613
  • 4
  • 17
  • Can you add more context to the question, and what have you tried till now. By name you mean the name of fields like `team_members.id`, `account` ? – Yash Joshi May 28 '20 at 06:58
  • Can you add what do you mean by name, for eg you can add what will be the sample output for the above mappings. – Yash Joshi May 28 '20 at 10:48
  • this is what I put as dummy . I want to get mapping details from my frontend. I want only those properties of particular index. Output should be the account, class, team_members.id, team_members.name, team_members.priority – Oshini May 28 '20 at 16:20

3 Answers3

0

Do you mean how to get the properties value in your object above from the front end as a prop? if so you can just destructure the prop in the function header. Instead of having (props) in function header, just use ({ mappings: { meeting: {properties}}}). You can then use the properties normally on the front end as an object type. For example:

const funComponent = ({ mappings: { meeting: {properties}}}) => {
 // properties can now be used inside this function anywhere as an object.
// for example properties.account or proprties.team_members
return (
  ...
);

};
Rahul Pillai
  • 187
  • 1
  • 9
  • no actually this mapping is in my backend. I want to get only the property names not the value , using elastic search query . backend is nodejs project and frontend is reactjs so frontend can access backend using elastic query – Oshini May 28 '20 at 08:27
  • If you want the property names (Keys) only for the entire object, you can use something like recursion to traverse through it and acquire key names. Check: https://stackoverflow.com/questions/42674473/get-all-keys-of-a-deep-object-in-javascript – Rahul Pillai May 28 '20 at 13:48
0

Loop the values

Object.values() - Get the object values

Object.keys() - Get the objects keys

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      mappings: {
        meeting: {
          properties: {
            account: { type: "integer" },
            class: { type: "keyword", normalizer: "my_normalizer" },
            team_members: {
              properties: {
                id: { type: "integer" },
                name: { type: "text" },
                priority: { type: "integer" }
              }
            }
          }
        }
      }
    };
  }
  render() {
    let dataValue = [];
    Object.values(this.state.mappings).forEach((ele, i) => {
      console.log(ele.properties.account.type);
      console.log(ele.properties.class.type);
      console.log(ele.properties.class.normalizer);
      dataValue.push(<li>{ele.properties.account.type}</li>)
    });
    return <div>{dataValue}</div>;
  }
}
export default App;
Sugumar K
  • 204
  • 2
  • 7
0

You need to call _mapping endpoint on the ElasticSearch Cluster with the index you want the mappings for. Ref: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html#view-mapping

At Frontend, you may have to write a parser that will take this mapping and return the fields. You will need custom logic to handle this.

The mappings you specified, I think belong to ElasticSearch v7.

Note: You may have to write your own parser logic in this case as there can be other solutions and each solution will depend on requirements.

Yash Joshi
  • 2,586
  • 1
  • 9
  • 18