rihad  
                
                  
                    September 17, 2020,  4:23pm
                   
                  1 
               
             
            
              Hi there! How do I use the must_exist alias attribute that appeared in version 7.9?
This is what I try:
curl -sS -X POST http://localhost:9200/_aliases?timeout=15m&master_timeout=15m -H Content-Type: application/json -d'
    {
      "actions" : [
        { "remove":     { "index" : "foo", "alias" : "bar", "must_exist": true } },
        { "add":        { "index" : "foo", "alias" : "baz" } }
      ]
    }'
And the result:
{
  "error": {
    "root_cause": [
      {
        "type": "x_content_parse_exception",
        "reason": "[4:131] [remove] unknown field [must_exist]"
      }
    ],
    "type": "x_content_parse_exception",
    "reason": "[4:145] [aliases] failed to parse field [actions]",
    "caused_by": {
      "type": "x_content_parse_exception",
      "reason": "[4:145] [alias_action] failed to parse field [remove]",
      "caused_by": {
        "type": "x_content_parse_exception",
        "reason": "[4:131] [remove] unknown field [must_exist]"
      }
    }
  },
  "status": 400
}
 
            
              
            
           
          
            
            
              @rihad  were you able to figure this out?
I can't find anything on this and it appears everything is correct.
The only thing I can think is to ensure you are on 7.9 since it only exists in that version. But since you specifically mentioned that I am guessing you are.
             
            
              
            
           
          
            
              
                rihad  
              
                  
                    September 18, 2020,  2:35pm
                   
                  3 
               
             
            
              I have no idea. Please note that attempting to use must_exist for "add" results in this error:
"[must_exist] is unsupported for [ADD]"
And mistyping the action like "ustexist": true, also for the "add" command, results in:
"[1:66] [add] unknown field [ustexist] did you mean [must_exist]?"
which suggests that this version (7.9.1) knows what must_exist is.
Both of these used for the "remove" command result in "unknown field XXX"
             
            
              
            
           
          
            
              
                rihad  
              
                  
                    September 18, 2020,  3:12pm
                   
                  4 
               
             
            
              I might be terribly wrong, but is it ok that must_exist is defined for the ADD parser (and not REMOVE)?
  
  
    
        } catch (IOException e) { 
            throw new ParsingException(parser.getTokenLocation(), "Problems parsing [filter]", e); 
        } 
    }, FILTER); 
    // Since we need to support numbers AND strings here we have to use ValueType.INT. 
    ADD_PARSER.declareField(AliasActions::routing, XContentParser::text, ROUTING, ValueType.INT); 
    ADD_PARSER.declareField(AliasActions::indexRouting, XContentParser::text, INDEX_ROUTING, ValueType.INT); 
    ADD_PARSER.declareField(AliasActions::searchRouting, XContentParser::text, SEARCH_ROUTING, ValueType.INT); 
    ADD_PARSER.declareField(AliasActions::writeIndex, XContentParser::booleanValue, IS_WRITE_INDEX, ValueType.BOOLEAN); 
    ADD_PARSER.declareField(AliasActions::isHidden, XContentParser::booleanValue, IS_HIDDEN, ValueType.BOOLEAN); 
    ADD_PARSER.declareField(AliasActions::mustExist, XContentParser::booleanValue, MUST_EXIST, ValueType.BOOLEAN); 
} 
private static final ObjectParser<AliasActions, Void> REMOVE_PARSER = parser(REMOVE.getPreferredName(), AliasActions::remove); 
private static final ObjectParser<AliasActions, Void> REMOVE_INDEX_PARSER = parser(REMOVE_INDEX.getPreferredName(), 
        AliasActions::removeIndex); 
 /** 
 * Parser for any one {@link AliasAction}. 
 */ 
public static final ConstructingObjectParser<AliasActions, Void> PARSER = new ConstructingObjectParser<>( 
        "alias_action", a -> { 
  
  
    
    
  
  
 
             
            
              
            
           
          
            
            
              @rihad  I tested and getting the same results as you. Taking a deeper look into, thanks.
             
            
              
            
           
          
            
            
              @rihad  I ran out of ideas so I opened up an issue on github  if you want to follow that also. Thank you.
             
            
              1 Like 
            
            
           
          
            
              
                system  
              
                  
                    October 16, 2020,  4:26pm
                   
                  7 
               
             
            
              This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.