Mapping JSON data with an elastic search cluster can be challenging, especially when dealing with a dynamic number of fields

I am currently developing an application where I need to map JSON data for storage in Elasticsearch. The challenge is that the number of fields in the JSON data is dynamic. How can I handle mapping in this scenario?

Mapping Snippet

var fs = uploadedFiles[0].fd;
var xlsxRows = require('xlsx-rows');
var rows = xlsxRows(fs);
console.log(rows);


     client.indices.putMapping({
            "index": "testindex",
            "type": "testtype",
            "body": {
                "testtype": {
                    "properties": {

                        "Field 1": {
                            "type": "string"
                        },
                        "Field 3": {
                            "type": "string"
                        },
                        "Field 2":{
                            "type":"string"
                        } .....
                       //Don't know how many fields are in json object.
                  } 
            }
        }
    }, function (err, response) {
            if(err){
                console.log("error");
            }
            console.log("REAPONCE")
            console.log(response);                                  

      });

This is a snippet of my sample JSON data //result of rows

 [
  { Name: 'paranthn', Age: '43', Address: 'trichy' },
  { Name: 'Arthick', Age: '23', Address: 'trichy' },
  { Name: 'vel', Age: '24', Address: 'trichy' } //property fields
  ]

NOTE: The number of property fields may vary dynamically.

Answer №1

ES always strives to accurately determine the types for fields in documents without mappings and set appropriate defaults.

A mapping becomes essential only when specific treatment is required for certain fields beyond the default settings, such as specifying analyzers for indexing or searching, determining if string fields should be analyzed, defining sub-fields with different analyzers, etc.

If these customizations are not needed, ES can automatically infer the mapping for your documents.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Styling the background of the endAdornment in a material-ui textfield using React

I tried following the instructions from this source: Unfortunately, the example code provided doesn't seem to be functioning properly now. Is there a way to achieve the same result without having that right margin so that it aligns better with the r ...

Enhancing the security of various components by utilizing secure HTTP-only cookies

Throughout my previous projects involving authentication, I have frequently utilized localstorage or sessionstorage to store the JWT. When attempting to switch to httpOnly secure cookies, I encountered a challenge in separating the header component from th ...

Is it necessary to include async/await in a method if there is already an await keyword where it is invoked?

Here are the two methods I have written in Typescript: async getCertURL(pol: string): Promise<string> { return await Api.getData(this.apiUrl + pol + this.certEndpoint, {timeout: 60000}).then( (response) => { return response.data.certUR ...

gulp-watch does not monitor files that are newly created or deleted

Currently working on a task: gulp.task('assetsInject', function () { gulp.src(paths.index) .pipe(plugins.inject( gulp.src(paths.scripts, {read: false}), { addRootSlash: false } ...

How to populate an ExtJS 3.4 combobox with local JSON data in a few simple steps

I am utilizing ExtJS 3.4 and in need of populating a combobox with specific data obtained from a previous XMLHttpRequest, stored in a variable as follows: my_variable = "[{"cod_domini":"1","nom_domini":"Sant Esteve de Palautordera"},{"cod_domini":"2","no ...

How can you create a jQuery fade in effect for a single <li> element

I'm in the process of developing a task management app that generates a new li element every time a user adds an item. However, I am facing an issue where fadeIn() is activating for every li on the page whenever a new item is added. Does anyone have s ...

Modifying nvarchar(max) fields in SQL Server with a vast amount of data

I am attempting to manually update a column in my SQL Server database that is of type nvarchar(max) with a large JSON string parsed as text. The query I am using is pretty straightforward: UPDATE Books SET Story = '' WHERE Id = 23 However, th ...

What is the best way to eliminate empty objects and arrays from JSON data?

{ "_class": "org.jenkinsci.plugins.workflow.job.WorkflowRun", "actions": [ { "date": "xyz", "lastBuiltRevision": { "branch": [ ...

Showcase JSON information in a format of a tabular display

Why can't I get the JSON data to display on my table view? I've tried fetching the JSON data, but I'm having trouble displaying it in a tabular format on the screen. import UIKit class User{ var userId : Int var id : Int var ti ...

Determine whether AngularJS directive method binding automatically defaults to angular.noop

In my directive, I am passing a function to a plugin which will use it with a specified value. Let's simplify things by ignoring data changes: angular.module('some.directives', []) .directive('myDirective', [, function () { ...

Ways to display a price near a whole number without using decimal points

Currently, I am working on an ecommerce project where the regular price of an item is $549. With a discount of 12.96% applied, the sale price comes down to $477.8496. However, I want the sale price to be displayed as either $477 or $478 for simplicity. Yo ...

Implementing bind to invoke a function during an onClick Event

Here is a code snippet I have been working on that demonstrates how to handle click events on hyperlinks. The code features two hyperlinks named A and B. When hyperlink A is clicked, the console will log 'You selected A', and when B is clicked, ...

Native Android application connected to a back-end service for user authentication

I am looking to develop a native Android application for a particular website. The primary challenge lies in figuring out how to implement the login functionality on the Android app, without altering the existing webservice site. The goal is for the Andro ...

Using TypeScript to Load JSON Data from a Folder

I'm a newcomer to TypeScript and encountering an issue. My task involves dynamically loading objects from a directory that houses multiple JSON files. The file names are generated through an export bash script populating the resource directory. I wan ...

Exploring the functionalities of class methods within an Angular export function

Is it possible to utilize a method from an exported function defined in a class file? export function MSALInstanceFactory(): IPublicClientApplication { return new PublicClientApplication({ auth: AzureService.getConfiguration(), <-------- Com ...

There was an error with JSON parsing in the fetch request due to an unexpected character found at line 1, column 2 of the JSON data

Currently, I am diving into learning JavaScript and the fetch API. As part of my practice, I am trying to retrieve exchange rate data from an API endpoint provided by a bank. However, I'm facing difficulties in parsing the response body into JSON form ...

Monitoring and refining console.error and console.log output in CloudWatch

I've encountered a situation where my lambda function includes both console.error and console.log statements, which Node.js interprets as stderr and stdout outputs respectively. However, upon viewing the logs in CloudWatch, I noticed that they appear ...

Error message 'MODULE_NOT_FOUND' occurs while executing a Docker application

Although I successfully created a docker image, I am encountering issues when trying to run it. This is the command that I am using for running: docker run coderpc/test-server Displayed below is the error message that appears in the console. Error: Canno ...

Utilizing Selenium Builder tests in combination with Jenkins and GitHub

My objective: Establishing a streamlined test framework utilizing Selenium Builder as a Firefox plugin, GitHub, and Jenkins. Storing the test files in .json format is essential for my workflow. At this point, I prefer to stay away from Java and Maven. My ...

Is it possible to include a visible comment in an ajax call that can be viewed in Fiddler when analyzing the outgoing data?

Here is an example of the code I am working with: $.ajax({ cache: false, url: "/xx" }).done(onAjaxDone).fail(function (jqXHR, textStatus, errorThrown) { Dialog.Alerts.ajaxOnFailure(jqXHR, textStatus, err ...