How to substitute all empty/blank values by "Others" in Elasticsearch?

Dinosaurius

When I create a pie chart, I want to substitute all empty values of a field myfield (i.e. equal to "") by "Others". How can I do it in Kibana?

If it's impossible to do in Kibana, then how can I do it using Elasticsearch.

enter image description here

UPDATE:

I executed this query and it didn't give me any error:

GET myindex/entry/_update_by_query
{
  "query":{
    "term": {
      "myfield.keyword": {
        "value": ""
      }
    }
  },
  "script":{
    "inline": "ctx._source.myfield = 'Other'",
    "lang": "painless"
  }
}

I get this output:

{
  "took": 5,
  "timed_out": false,
  "total": 0,
  "updated": 0,
  "deleted": 0,
  "batches": 0,
  "version_conflicts": 0,
  "noops": 0,
  "retries": {
    "bulk": 0,
    "search": 0
  },
  "throttled_millis": 0,
  "requests_per_second": -1,
  "throttled_until_millis": 0,
  "failures": []
}

But when I check the values of myfield, I get the value "" again, instead of Other.

GET myindex/_search?
{
 "size":0,
   "aggs": {
    "months": {
     "terms" : {
      "field": "myfield"
     }
    }
   }
}

This is my index mapping:

PUT /myindex
{
    "mappings": {
      "entry": {
      "_all": {
        "enabled": false
      },
        "properties": {
          "Id": {
            "type":"keyword"
          },
          "Country": {
            "type":"keyword"
          },
          "myfield": {
            "type":"keyword"
          },
          "Year": {
            "type":"integer"
          },
          "Counter": {
            "type":"integer"
          }
        }
      }
    }
}
Hatim Stovewala

As far as I know, this cannot be done at Kibana's end. You can update all your empty field documents with "Others" in Elasticsearch index.

To update on Elasticsearch end, you can use Update By Query API. Below is the update code/query.

GET myindex/entry/_update_by_query
{
  "query":{
    "term": {
      "myfield": {
        "value": ""
      }
    }
  },
  "script":{
    "inline": "ctx._source.myfield = 'Other'",
    "lang": "painless"
  }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Elasticsearch must some values and must not all others

How to substitute all values of a certain key in an array of JSON objects

How to substitute a certain letter without substituting others?

How to substitute values in SymPy object?

How to substitute values to Ansible template

Substitute pixels values of all layers in a raster stack

How to query all values of a nested field with Elasticsearch

How to replace all the various empty values in a dataframe so that they are all NaN, not '-' or others

Insert values and default on all others columns

Keep specific values in a dataframe and delete all the others

How to substitute particular values of POST query for InvokeHTTP?

How to substitute values in file between 2 strings

how to elegantly substitute repeated values with a different vector?

How to substitute values in mathematics equations in python?

Gatling how to substitute the dynamic values captured to a list

How to substitute values in matrix operation without solving?

Laravel, how to substitute a variable in all urls of the project

How to get sed to substitute for all but one character

python substitute substring with multiple values with all possible combinations

Most generic way to Substitute all the occurrences of a string with different values Python

How to highlight all the values in Elasticsearch which matches the string

How do I get all values for a nested field using elasticsearch?

How to substitute NaN values of a column based on the values of another column?

How can I substitute null values by average values in PYSPARK?

How to substitute specific values in multiple columns with corresponding values of another dataframe?

How to insert values of a dataframe to others dataframe

How to create a dll that includes all the others?

How to sum all titles even others are empty

How to bring a specifc view above all others?