Navigation

Path Construction

The path parameter is used by the Full Text Search operators to specify the field or fields to be searched. It may contain:

  • A string
  • An array of strings
  • A multi analyzer specification
  • An array containing a combination of strings and multi analyzer specifications

To search only a single indexed field, use a quoted string in the path parameter. The following example searches a field named description.

"path": "description"

To search multiple indexed fields, use an array of quoted strings in the path parameter. Documents which match on any of the specified fields are included in the result set. The following example searches the description and type fields.

"path": ["description", "type"]

If your index definition contains a field with multiple analyzers, you can specify which one to use. The path parameter can take an object with the following fields:

Field Description
value The name of the field to search.
multi The name of the alternate analyzer specified in a multi object in an index definition.

In the following index definition, fields named names and notes use the standard analyzer. A field named comments uses standard as its default analyzer, and it also specifies a multi named mySecondaryAnalyzer which uses the lucene.whitespace analyzer.

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "names": {
        "type": "string",
        "analyzer": "lucene.standard"
      },
      "notes": {
        "type": "string",
        "analyzer": "lucene.standard"
      },
      "comments": {
        "type": "string",
        "analyzer": "lucene.standard",
        "multi": {
          "mySecondaryAnalyzer": {
            "analyzer": "lucene.whitespace",
            "type": "string"
          }
        }
      }
    }
  }
}

The following path example searches the comments field using the multi named mySecondaryAnalyzer in the index definition.

"path": { "value": "comments", "multi": "mySecondaryAnalyzer" }

To search a combination of indexed fields and fields with multiple analyzers, use an array. The following example searches the names and notes fields with the default analyzer, and the comments field using the multi named mySecondaryAnalyzer in the index definition.

"path": [ "names", "notes", { "value": "comments", "multi": "mySecondaryAnalyzer" } ]

Examples

The following examples use a collection named cars which has the following documents:

{
  "_id" : 1,
  "type" : "sedan",
  "make" : "Toyota",
  "description" : "Blue four-door sedan, lots of trunk space."
}
{
  "_id" : 2,
  "type" : "coupe",
  "make" : "BMW",
  "description" : "Red two-door convertible, driver's-side airbag."
}
{
  "_id" : 3,
  "type" : "SUV",
  "make" : "Ford",
  "description" : "Black four-door SUV, three rows of seats."
}

The index definition for the cars collection is as follows:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "make": {
        "type": "string",
        "analyzer": "lucene.standard"
      },
      "description": {
        "type": "string",
        "analyzer": "lucene.standard",
        "multi": {
          "simpleAnalyzer": {
            "analyzer": "lucene.simple",
            "type": "string"
          }
        }
      }
    }
  }
}

The above index definition specifies that the make field is indexed with the standard analyzer. The description field uses the standard analyzer by default, but it can also use the simple analyzer by specifying simpleAnalyzer with the multi parameter.