Skip to content

Phrase queries in Elasticsearch 6 #1261

@nickpeihl

Description

@nickpeihl

Hey all. I wanted to reach out about your efforts to migrate to Elasticsearch 6. I'm very interested in helping out.

Many of the phrase queries in the unit test fixtures of pelias/api fail because the match queries have a type: 'phrase' parameter that is no longer supported in Elasticsearch 6+. This has been replaced by the match_phrase query type.

The match_phrase query type does not support cutoff_frequency and operator parameters. However, these parameters are still supported in the match query type. The match query type no longer supports slop.

For an example, let's look at https://github.com/pelias/api/blob/master/test/unit/fixture/autocomplete_boundary_country.js. There are two possible ways to make it compatibile with ES 6.

diff --git a/test/unit/fixture/autocomplete_boundary_country.js b/test/unit/fixture/autocomplete_boundary_country.js
index 5da3698..2ad0df6 100644
--- a/test/unit/fixture/autocomplete_boundary_country.js
+++ b/test/unit/fixture/autocomplete_boundary_country.js
@@ -3,16 +3,14 @@ module.exports = {
     'bool': {
       'must': [{
         'constant_score': {
-          'query': {
+          'filter': {
             'match': {
               'name.default': {
                 'analyzer': 'peliasQueryPartialToken',
                 'boost': 100,
                 'query': 'test',
                 'cutoff_frequency': 0.01,
-                'type': 'phrase',
-                'operator': 'and',
-                'slop': 3
+                'operator': 'and'
               }
             }
           }
diff --git a/test/unit/fixture/autocomplete_boundary_country.js b/test/unit/fixture/autocomplete_boundary_country.js
index 5da3698..6b1e87e 100644
--- a/test/unit/fixture/autocomplete_boundary_country.js
+++ b/test/unit/fixture/autocomplete_boundary_country.js
@@ -3,15 +3,12 @@ module.exports = {
     'bool': {
       'must': [{
         'constant_score': {
-          'query': {
-            'match': {
+          'filter': {
+            'match_phrase': {
               'name.default': {
                 'analyzer': 'peliasQueryPartialToken',
                 'boost': 100,
                 'query': 'test',
-                'cutoff_frequency': 0.01,
-                'type': 'phrase',
-                'operator': 'and',
                 'slop': 3
               }
             }

I'm not sure which is the preferred solution. So I'm reaching out for your thoughts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions