in server/src/main/java/org/opensearch/cluster/node/DiscoveryNodeFilters.java [145:265]
public boolean match(DiscoveryNode node) {
for (Map.Entry<String, String[]> entry : filters.entrySet()) {
String attr = entry.getKey();
String[] values = entry.getValue();
if ("_ip".equals(attr)) {
// We check both the host_ip or the publish_ip
String publishAddress = null;
if (node.getAddress() instanceof TransportAddress) {
publishAddress = NetworkAddress.format(node.getAddress().address().getAddress());
}
boolean match = matchByIP(values, node.getHostAddress(), publishAddress);
if (opType == OpType.AND) {
if (match) {
// If we match, we can check to the next filter
continue;
}
return false;
}
if (match && opType == OpType.OR) {
return true;
}
} else if ("_host_ip".equals(attr)) {
// We check explicitly only the host_ip
boolean match = matchByIP(values, node.getHostAddress(), null);
if (opType == OpType.AND) {
if (match) {
// If we match, we can check to the next filter
continue;
}
return false;
}
if (match && opType == OpType.OR) {
return true;
}
} else if ("_publish_ip".equals(attr)) {
// We check explicitly only the publish_ip
String address = null;
if (node.getAddress() instanceof TransportAddress) {
address = NetworkAddress.format(node.getAddress().address().getAddress());
}
boolean match = matchByIP(values, address, null);
if (opType == OpType.AND) {
if (match) {
// If we match, we can check to the next filter
continue;
}
return false;
}
if (match && opType == OpType.OR) {
return true;
}
} else if ("_host".equals(attr)) {
for (String value : values) {
if (Regex.simpleMatch(value, node.getHostName()) || Regex.simpleMatch(value, node.getHostAddress())) {
if (opType == OpType.OR) {
return true;
}
} else {
if (opType == OpType.AND) {
return false;
}
}
}
} else if ("_id".equals(attr)) {
for (String value : values) {
if (node.getId().equals(value)) {
if (opType == OpType.OR) {
return true;
}
} else {
if (opType == OpType.AND) {
return false;
}
}
}
} else if ("_name".equals(attr) || "name".equals(attr)) {
for (String value : values) {
if (Regex.simpleMatch(value, node.getName())) {
if (opType == OpType.OR) {
return true;
}
} else {
if (opType == OpType.AND) {
return false;
}
}
}
} else {
String nodeAttributeValue = node.getAttributes().get(attr);
if (nodeAttributeValue == null) {
if (opType == OpType.AND) {
return false;
} else {
continue;
}
}
for (String value : values) {
if (Regex.simpleMatch(value, nodeAttributeValue)) {
if (opType == OpType.OR) {
return true;
}
} else {
if (opType == OpType.AND) {
return false;
}
}
}
}
}
if (opType == OpType.OR) {
return false;
} else {
return true;
}
}