index_prefixes

index_prefixes

The index_prefixes parameter enables the indexing of term prefixes to speed up prefix searches. It accepts the following optional settings:

min_chars

The minimum prefix length to index. Must be greater than 0, and defaults to 2. The value is inclusive.

max_chars

The maximum prefix length to index. Must be less than 20, and defaults to 5. The value is inclusive.

This example creates a text field using the default prefix length settings:

  1. resp = client.indices.create(
  2. index="my-index-000001",
  3. mappings={
  4. "properties": {
  5. "body_text": {
  6. "type": "text",
  7. "index_prefixes": {}
  8. }
  9. }
  10. },
  11. )
  12. print(resp)
  1. response = client.indices.create(
  2. index: 'my-index-000001',
  3. body: {
  4. mappings: {
  5. properties: {
  6. body_text: {
  7. type: 'text',
  8. index_prefixes: {}
  9. }
  10. }
  11. }
  12. }
  13. )
  14. puts response
  1. const response = await client.indices.create({
  2. index: "my-index-000001",
  3. mappings: {
  4. properties: {
  5. body_text: {
  6. type: "text",
  7. index_prefixes: {},
  8. },
  9. },
  10. },
  11. });
  12. console.log(response);
  1. PUT my-index-000001
  2. {
  3. "mappings": {
  4. "properties": {
  5. "body_text": {
  6. "type": "text",
  7. "index_prefixes": { }
  8. }
  9. }
  10. }
  11. }

An empty settings object will use the default min_chars and max_chars settings

This example uses custom prefix length settings:

  1. resp = client.indices.create(
  2. index="my-index-000001",
  3. mappings={
  4. "properties": {
  5. "full_name": {
  6. "type": "text",
  7. "index_prefixes": {
  8. "min_chars": 1,
  9. "max_chars": 10
  10. }
  11. }
  12. }
  13. },
  14. )
  15. print(resp)
  1. response = client.indices.create(
  2. index: 'my-index-000001',
  3. body: {
  4. mappings: {
  5. properties: {
  6. full_name: {
  7. type: 'text',
  8. index_prefixes: {
  9. min_chars: 1,
  10. max_chars: 10
  11. }
  12. }
  13. }
  14. }
  15. }
  16. )
  17. puts response
  1. const response = await client.indices.create({
  2. index: "my-index-000001",
  3. mappings: {
  4. properties: {
  5. full_name: {
  6. type: "text",
  7. index_prefixes: {
  8. min_chars: 1,
  9. max_chars: 10,
  10. },
  11. },
  12. },
  13. },
  14. });
  15. console.log(response);
  1. PUT my-index-000001
  2. {
  3. "mappings": {
  4. "properties": {
  5. "full_name": {
  6. "type": "text",
  7. "index_prefixes": {
  8. "min_chars" : 1,
  9. "max_chars" : 10
  10. }
  11. }
  12. }
  13. }
  14. }