Error "Look-behind group does not have an obvious maximum length near index" in pattern_capture

Hello

I just want to index the word "Samsung" in the text below

Text: Samsung a30 mobile phone

I mean I want to separate the text above by space and just index the word I want (the word may change by location, for example I might want to index the third or second word of the text)

I use pattern_capture to do this

Pattern: (?<=^(\W+\s){1})(\w+)
But I get the following error

Error:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "pattern_syntax_exception",
        "reason" : "Look-behind group does not have an obvious maximum length near index 14\n(?<=^(\\w+\\s){1})(\\w+)\n              ^"
      }
    ],
    "type" : "pattern_syntax_exception",
    "reason" : "Look-behind group does not have an obvious maximum length near index 14\n(?<=^(\\w+\\s){1})(\\w+)\n              ^"
  },
  "status" : 400
}

Do you have a solution?

To do this you must use the predicate_token_filter filter

Sample code:

GET /_analyze
{
  "tokenizer": "whitespace",
  "filter": [
    {
      "type": "predicate_token_filter",
      "script": {
        "source": """
          token.getPosition() === 0
        """
      }
    }
  ],
  "text": "the fox jumps the lazy dog"
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.