ElasticGraph Query API: Full Text Search

ElasticGraph supports two full-text search filtering predicates:

matchesPhrase
Matches records where the field value has a phrase matching the provided phrase using full text search. This is stricter than matchesQuery: all terms must match and be in the same order as the provided phrase.

Will be ignored when null is passed.

matchesQuery
Matches records where the field value matches the provided query using full text search. This is more lenient than matchesPhrase: the order of terms is ignored, and, by default, only one search term is required to be in the field value.

Will be ignored when null is passed.

Matches Query

matchesQuery is the more lenient of the two predicates. It’s designed to match broadly. Here’s an example:

query AccordionOrViolinSearch {
  artists(filter: {
    bio: {
      description: {
        matchesQuery: {
          query: "accordion violin"
        }
      }
    }
  }) {
    nodes {
      name
      bio {
        description
      }
    }
  }
}

This query will match artists with bios like:

Renowned for his mesmerizing performances, Luca “The Breeze” Fontana captivates audiences with his accordion, weaving intricate melodies that dance between the notes of traditional folk and modern jazz.

Sylvia Varela’s avant-garde violin playing defies tradition, blending haunting dissonance with unexpected rhythms.

Notably, the description needs accordion OR violin, but not both. In addition, it would match an artist bio that mentioned “viola” since it supports fuzzy matching by default and “viola” is only 2 edits away from “violin”. Arguments are supported to control both aspects to make matching stricter:

query AccordionAndViolinStrictSearch {
  artists(filter: {
    bio: {
      description:{
        matchesQuery: {
          query: "accordion violin"
          requireAllTerms: true
          allowedEditsPerTerm: NONE
        }
      }
    }
  }) {
    nodes {
      name
      bio {
        description
      }
    }
  }
}

Matches Phrase

matchesPhrase is even stricter: it requires all terms in the provided order (matchesQuery doesn’t care about order). It’s particularly useful when you want to search on a particular multi-word expression:

query PhraseSearch {
  artists(filter: {
    bio: {
      description:{
        matchesPhrase: {
          phrase: "Ed Sullivan Show"
        }
      }
    }
  }) {
    nodes {
      name
      bio {
        description
      }
    }
  }
}

Bypassing matchesPhrase and matchesQuery

In order to make a matchesPhrase or matchesQuery filter optional, you can supply null to the MatchesQueryFilterInput parameter, like this:

query OptionalMatchingFilter(
  $optionalMatchQuery: MatchesQueryFilterInput = null
) {
  artists(filter: {
    bio: {
      description: {
        matchesQuery: $optionalMatchQuery
      }
    }
  }) {
    nodes {
      name
      bio {
        description
      }
    }
  }
}