

Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.

# Adición de un tesauro a un índice
<a name="index-synonyms-adding-thesaurus-file"></a>

Los siguientes procedimientos muestran cómo agregar un archivo de sinónimos a un índice. Puede tardar de hasta 30 minutos en ver los efectos del archivo de sinónimos actualizado. Para más información sobre el archivo del tesauro, véase [Crear un archivo de tesauro](index-synonyms-creating-thesaurus-file.md). 

------
#### [ Console ]

**Para agregar un diccionario de sinónimos**

1. En el panel de navegación izquierdo, bajo el índice donde desea añadir una lista de sinónimos, su tesauro, seleccione **Sinónimos**. 

1. En la página de **Sinónimos**, elija **Añadir tesauro**. 

1. En **Definir tesauro**, asigne un nombre al tesauro y, si lo desea, una descripción.

1. En **la configuración del tesauro**, indique la Amazon S3 ruta al archivo del tesauro. El archivo debe tener un tamaño inferior a 5 MB.

1. En **Función de IAM**, seleccione una función o seleccione **Crear una nueva función** y especifique un nombre de función para crear una nueva función. Amazon Kendra utiliza este rol para acceder al Amazon S3 recurso en su nombre. El rol de IAM tiene el prefijo "AmazonKendra-». 

1. Seleccione **Guardar** para guardar la configuración y añadir el tesauro. Una vez ingerido, el tesauro se activa y los sinónimos aparecen resaltados en los resultados. Puede tardar hasta 30 minutos en ver los efectos de su archivo de tesauro. 

------
#### [ CLI ]

Para añadir un tesario a un índice con el, llame a: AWS CLI`create-thesaurus` 

```
aws kendra create-thesaurus \
--index-id {{index-id}} \
--name "{{thesaurus-name}}" \
--description "{{thesaurus-description}}" \
--source-s3-path "Bucket={{bucket-name}},Key={{thesaurus/synonyms.txt}}" \
--role-arn {{role-arn}}
```

Llame a `list-thesauri` para ver una lista de tesauros:

```
aws kendra list-thesauri \
--index-id {{index-id}}
```

Para ver los detalles de un tesauro, llame a `describe-thesaurus`:

```
aws kendra describe-thesaurus \
--index-id {{index-id}} \
--index-id {{thesaurus-id}}
```

Puede tardar hasta 30 minutos en ver los efectos de su archivo de tesauro.

------
#### [ Python ]

```
import boto3
from botocore.exceptions import ClientError
import pprint
import time

kendra = boto3.client("kendra")

print("Create a thesaurus")

thesaurus_name = "{{thesaurus-name}}"
thesaurus_description = "{{thesaurus-description}}"
thesaurus_role_arn = "{{role-arn}}"

index_id = "{{index-id}}"

s3_bucket_name = "{{bucket-name}}"
s3_key = "{{thesaurus-file}}"
source_s3_path= {
    'Bucket': s3_bucket_name,
    'Key': s3_key
}

try:
    thesaurus_response = kendra.create_thesaurus(
        Description = thesaurus_description,
        Name = thesaurus_name,
        RoleArn = thesaurus_role_arn,
        IndexId = index_id,
        SourceS3Path = source_s3_path
    )

    pprint.pprint(thesaurus_response)

    thesaurus_id = thesaurus_response["Id"]

    print("Wait for Kendra to create the thesaurus.")

    while True:
        # Get thesaurus description
        thesaurus_description = kendra.describe_thesaurus(
            Id = thesaurus_id,
            IndexId = index_id
        )
        # If status is not CREATING quit
        status = thesaurus_description["Status"]
        print("Creating thesaurus. Status: " + status)
        if status != "CREATING":
            break
        time.sleep(60)

except ClientError as e:
        print("%s" % e)

print("Program ends.")
```

------
#### [ Java ]

```
package com.amazonaws.kendra;

import software.amazon.awssdk.services.kendra.KendraClient;
import software.amazon.awssdk.services.kendra.model.CreateThesaurusRequest;
import software.amazon.awssdk.services.kendra.model.CreateThesaurusResponse;
import software.amazon.awssdk.services.kendra.model.DescribeThesaurusRequest;
import software.amazon.awssdk.services.kendra.model.DescribeThesaurusResponse;
import software.amazon.awssdk.services.kendra.model.S3Path;
import software.amazon.awssdk.services.kendra.model.ThesaurusStatus;

public class CreateThesaurusExample {

  public static void main(String[] args) throws InterruptedException {

    KendraClient kendra = KendraClient.builder().build();

    String thesaurusName = "{{thesaurus-name}}";
    String thesaurusDescription = "{{thesaurus-description}}";
    String thesaurusRoleArn = "{{role-arn}}";

    String s3BucketName = "{{bucket-name}}";
    String s3Key = "{{thesaurus-file}}";
    String indexId = "{{index-id}}";

    System.out.println(String.format("Creating a thesaurus named %s", thesaurusName));
    CreateThesaurusRequest createThesaurusRequest = CreateThesaurusRequest
        .builder()
        .name(thesaurusName)
        .indexId(indexId)
        .description(thesaurusDescription)
        .roleArn(thesaurusRoleArn)
        .sourceS3Path(S3Path.builder()
            .bucket(s3BucketName)
            .key(s3Key)
            .build())
        .build();
    CreateThesaurusResponse createThesaurusResponse = kendra.createThesaurus(createThesaurusRequest);
    System.out.println(String.format("Thesaurus response %s", createThesaurusResponse));

    String thesaurusId = createThesaurusResponse.id();

    System.out.println(String.format("Waiting until the thesaurus with ID %s is created.", thesaurusId));

    while (true) {
      DescribeThesaurusRequest describeThesaurusRequest = DescribeThesaurusRequest.builder()
          .id(thesaurusId)
          .indexId(indexId)
          .build();
      DescribeThesaurusResponse describeThesaurusResponse = kendra.describeThesaurus(describeThesaurusRequest);
      ThesaurusStatus status = describeThesaurusResponse.status();
      if (status != ThesaurusStatus.CREATING) {
        break;
      }

      TimeUnit.SECONDS.sleep(60);
    }

    System.out.println("Thesaurus creation is complete.");
  }
}
```

------