Changing autocomplete pipeline to full string

I am using the code below as part of an autocomplete search.
Now I want to change this to a search of the complete searchString.

I can’t seem to get it work.

		return new BsonDocument("autocomplete",
			new BsonDocument
			{
				{ "query", searchString.Trim() },
				{ "path", field }
			});

Thanks for all help.

Regards

Ad

Hi @Ad_Kerremans1 , can you share a copy of your index definition and a sample document + searchString that you are trying to match? Generally, the autocomplete field mapping type and operator are a good fit for searching partial words. However, if searchString exceeds the maxGram configured in the search index, this might lead to unexpected documents being returned in your search. When using autocomplete, it’s best to choose a maxGram which will support the expected length of searchString . It’s important to note that configuring a large maxGram (e.g… 15+) can dramatically increase the size of your index, so it’s important to select a maxGram which balances your search requirements and storage constraints.

Alternatively, if you want to match complete words, you can try the text operator or equals for an exact string match.

BTW, the Search Playground is a great tool to help test different indexes and queries.

Hi @amyjian ,

This is my atlas search

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "barcodes": {
        "fields": {
          "barcode": [
            {
              "dynamic": true,
              "type": "document"
            },
            {
              "maxGrams": 13,
              "minGrams": 3,
              "tokenization": "nGram",
              "type": "autocomplete"
            }
          ]
        },
        "type": "document"
      },
      "externalId": [
        {
          "maxGrams": 20,
          "minGrams": 3,
          "tokenization": "nGram",
          "type": "autocomplete"
        }
      ],
      "isActive": [
        {
          "type": "boolean"
        }
      ],
      "itemGroups": [
        {
          "dynamic": true,
          "type": "document"
        },
        {
          "maxGrams": 20,
          "minGrams": 3,
          "tokenization": "nGram",
          "type": "autocomplete"
        }
      ],
      "name": [
        {
          "maxGrams": 20,
          "minGrams": 3,
          "tokenization": "nGram",
          "type": "autocomplete"
        },
        {
          "normalizer": "lowercase",
          "type": "token"
        }
      ],
      "searchTerms": [
        {
          "dynamic": true,
          "type": "document"
        },
        {
          "maxGrams": 20,
          "minGrams": 3,
          "tokenization": "nGram",
          "type": "autocomplete"
        }
      ]
    }
  }
}

The problem is in the itemGroups

image

When the itemgroup contains an entry with and & in it the search fails.
What I want to achieve is to search on the full string of the itemGroups.

Regards

Ad