Home > Mobile >  Open Search, exclude field from indexing in mapping
Open Search, exclude field from indexing in mapping

Time:06-10

I have the following mapping:

{
  "properties": {
    "type": {
      "type": "keyword"
    },
    "body": {
      "type": "text"
    },
    "id": {
      "type": "keyword"
    },
    "date": {
     "type": "date"
    },
  },
}

body field is going to be an email message, it's very long and I don't want to index it.

what is the proper way to exclude this field from indexing?

What I tried:

enabled: false - as I understand from the documentation, it's applied only to object type fields but in my case it's not really an object so I'm not sure whether I can use it.

index: false/'no' - this breaks the code at all and does not allow me to make a search. My query contains query itself and aggregations with filter. Filter contains range:

date: { gte: someDay.getTime(), lte: 'now' }

P.S. someDay is a certain day in my case.

The error I get after applying index: false in mapping to the body field is the following:

{
    "error":
    {
        "root_cause":
        [
            {
                "type": "number_format_exception",
                "reason": "For input string: \"now\""
            }
        ],
        "type": "search_phase_execution_exception",
        "reason": "all shards failed",
        "phase": "query",
        "grouped": true,
        "failed_shards":
        [
            {
                "shard": 0,
                "index": "test",
                "node": "eehPq21jQsmkotVOqQEMeA",
                "reason":
                {
                    "type": "number_format_exception",
                    "reason": "For input string: \"now\""
                }
            }
        ],
        "caused_by":
        {
            "type": "number_format_exception",
            "reason": "For input string: \"now\"",
            "caused_by":
            {
                "type": "number_format_exception",
                "reason": "For input string: \"now\""
            }
        }
    },
    "status": 400
}

I'm not sure how these cases are associated as the error is about date field while I'm adding index property to body field.

I'm using: "@opensearch-project/opensearch": "^1.0.2"

Please help me to understand:

  1. how to exclude field from indexing.
  2. why applying index: false to body field in mapping breaks the code an I get an error associated with date field.

CodePudding user response:

You should just modify your mapping to this:

"body": {
   "type": "text",
   "index": false
}

And it should work

  • Related