Elasticsearch I/O 内联整理查询的建议阶段异常

Elasticsearch I/O exception during suggest phase with an inline collate query

我在 ES 5.2 的 phrase_suggestion 查询中有一个整理查询。为此,我的整理查询是一个内联小胡子模板。但是,我收到一个 I/O 异常错误,告诉我当我使用 toJson mustache 标记将过滤器对象传递到我的查询时出现意外的 '}' 字符。

令人惊讶的是,当我使用 _search/template 端点时,我的查询模板似乎没问题。通过这种方式我没有得到任何错误。

这是我的查询:

{
    "index": "arrets27",
    "type": "arret",
    "body": {

        "suggest": {
            "text": "secs, Bovero,",
            "simple_phrase": {
                "phrase": {
                    "field": "contenu_html.trigram",
                    "size": 1,
                    "gram_size": 3,
                    "max_errors": 2,
                    "confidence": 2.5,
                    "direct_generator": [{
                        "field": "contenu_html.trigram",
                        "suggest_mode": "always"
                    }, {
                        "field": "contenu_html.reverse",
                        "suggest_mode": "always",
                        "pre_filter": "reverse",
                        "post_filter": "reverse"
                    }, {
                        "field": "contenu_html.nostem_with_accents",
                        "suggest_mode": "missing"
                    }],
                    "collate": {
                        "query": {
                            "params": {
                                "filters": [{
                                    "bool": {
                                        "should": [{
                                            "term": {
                                                "juridiction.raw": "CE"
                                            }
                                        }]
                                    }
                                }, {
                                    "bool": {
                                        "should": [{
                                            "term": {
                                                "search_access.raw": "ALL"
                                            }
                                        }, {
                                            "term": {
                                                "search_access.raw": "FREE_TRIAL"
                                            }
                                        }, {
                                            "term": {
                                                "search_access.raw": "RESTRICTED"
                                            }
                                        }]
                                    }
                                }]
                            },
                            "inline": "{\"bool\":{\"must\":[{\"multi_match\":{\"query\":\"{{suggestion}}\",\"analyzer\":\"query_analyzer\",\"type\":\"cross_fields\",\"fields\":[\"doc_id^2\",\"search_title^0.1\",\"formation^2\",\"form_dec_att^1\",\"president^1\",\"avocat_gl^1\",\"avocats^1\",\"rapporteur^1\",\"commissaire_gvt^1\",\"citation_jp^0.05\",\"keywords^2\",\"liens^2\",\"numero^4\",\"numero_affaire^4\",\"other_numbers^4\",\"solution^2\",\"nature^2\",\"ville^2\",\"siege_appel^2\",\"juri_prem^2\",\"lieu_prem^2\",\"ecli^2\",\"reference_url^2\",\"wikipedia^100\",\"ancien_id^2\",\"type_rec^2\",\"nor^2\",\"nature_qualifiee^2\",\"loi_def^2\",\"titre_jo^2\",\"loi_def_nor^2\",\"loi_def_num^2\",\"saisines^2\",\"observations^2\",\"publi_bull_ref^4\",\"ref_numeros_affaires^2\",\"organisations^2\",\"issue^2\",\"resolution_number^2\",\"doctype_branch^2\",\"legifrance_ref^2\",\"reference_citation^2\",\"inpi_ref^2\",\"inpi_partan^0.1\",\"inpi_marq^0.1\",\"inpi_prod^2\",\"inpi_ti^2\",\"inpi_obj^2\",\"inpi_cib^2\",\"inpi_ct^2\",\"demandeurs_names^0.1\",\"defendeurs_names^0.1\",\"comment_titles^1\",\"citation_titles^0.1\",\"contenu_html^1\",\"saisines_html^2\",\"observations_html^2\",\"sommaire_ana^2\",\"comment_contents^0.5\",\"citation_contents^0.05\"],\"operator\":\"and\"}}],\"filter\":{{#toJson}}filters{{/toJson}}}}"
                        },
                        "prune": true
                    }
                }
            }
        }
    }
}

这是我在 ES 中得到的错误日志:

[2017-05-30T12:34:32,697][DEBUG][o.e.a.s.TransportSearchAction] [index-dev1] [arrets27][4], node[rpBSnTFORcmlVzldTfAGYA], [P], s[STARTED], a[id=6P0qTS-CTxC-TYA5mQ041w]: Failed to execute [SearchRequest{searchType=QUERY_THEN_FETCH, indices=[arrets27], indicesOptions=IndicesOptions[id=38, ignore_unavailable=false, allow_no_indices=true, expand_wildcards_open=true, expand_wildcards_closed=false, allow_alisases_to_multiple_indices=true, forbid_closed_indices=true], types=[arret], routing='null', preference='null', requestCache=false, scroll=null, source={
  "suggest" : {
    "text" : "secs, Bovero,",
    "simple_phrase" : {
      "phrase" : {
        "field" : "contenu_html.trigram",
        "size" : 1,
        "real_word_error_likelihood" : 0.95,
        "confidence" : 2.5,
        "separator" : " ",
        "max_errors" : 2.0,
        "gram_size" : 3,
        "force_unigrams" : true,
        "token_limit" : 10,
        "direct_generator" : [
          {
            "field" : "contenu_html.trigram",
            "suggest_mode" : "always"
          },
          {
            "field" : "contenu_html.reverse",
            "pre_filter" : "reverse",
            "post_filter" : "reverse",
            "suggest_mode" : "always"
          },
          {
            "field" : "contenu_html.nostem_with_accents",
            "suggest_mode" : "missing"
          }
        ],
        "collate" : {
          "query" : {
            "inline" : "{\"bool\":{\"must\":[{\"multi_match\":{\"query\":\"{{suggestion}}\",\"analyzer\":\"query_analyzer\",\"type\":\"cross_fields\",\"fields\":[\"doc_id^2\",\"search_title^0.1\",\"formation^2\",\"form_dec_att^1\",\"president^1\",\"avocat_gl^1\",\"avocats^1\",\"rapporteur^1\",\"commissaire_gvt^1\",\"citation_jp^0.05\",\"keywords^2\",\"liens^2\",\"numero^4\",\"numero_affaire^4\",\"other_numbers^4\",\"solution^2\",\"nature^2\",\"ville^2\",\"siege_appel^2\",\"juri_prem^2\",\"lieu_prem^2\",\"ecli^2\",\"reference_url^2\",\"wikipedia^100\",\"ancien_id^2\",\"type_rec^2\",\"nor^2\",\"nature_qualifiee^2\",\"loi_def^2\",\"titre_jo^2\",\"loi_def_nor^2\",\"loi_def_num^2\",\"saisines^2\",\"observations^2\",\"publi_bull_ref^4\",\"ref_numeros_affaires^2\",\"organisations^2\",\"issue^2\",\"resolution_number^2\",\"doctype_branch^2\",\"legifrance_ref^2\",\"reference_citation^2\",\"inpi_ref^2\",\"inpi_partan^0.1\",\"inpi_marq^0.1\",\"inpi_prod^2\",\"inpi_ti^2\",\"inpi_obj^2\",\"inpi_cib^2\",\"inpi_ct^2\",\"demandeurs_names^0.1\",\"defendeurs_names^0.1\",\"comment_titles^1\",\"citation_titles^0.1\",\"contenu_html^1\",\"saisines_html^2\",\"observations_html^2\",\"sommaire_ana^2\",\"comment_contents^0.5\",\"citation_contents^0.05\"],\"operator\":\"and\"}}],\"filter\":{{#toJson}}filters{{/toJson}}}}",
            "lang" : "mustache",
            "params" : {
              "filters" : [
                {
                  "bool" : {
                    "should" : [
                      {
                        "term" : {
                          "juridiction.raw" : "CE"
                        }
                      }
                    ]
                  }
                },
                {
                  "bool" : {
                    "should" : [
                      {
                        "term" : {
                          "search_access.raw" : "ALL"
                        }
                      },
                      {
                        "term" : {
                          "search_access.raw" : "FREE_TRIAL"
                        }
                      },
                      {
                        "term" : {
                          "search_access.raw" : "RESTRICTED"
                        }
                      }
                    ]
                  }
                }
              ]
            }
          },
          "prune" : true
        }
      }
    }
  }
}}]
org.elasticsearch.transport.RemoteTransportException: [index-dev1][172.31.26.119:9300][indices:data/read/search[phase/query]]
Caused by: org.elasticsearch.ElasticsearchException: I/O exception during suggest phase
    at org.elasticsearch.search.suggest.SuggestPhase.execute(SuggestPhase.java:72) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:94) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.search.SearchService.loadOrExecuteQueryPhase(SearchService.java:246) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:260) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.action.search.SearchTransportService.messageReceived(SearchTransportService.java:298) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.action.search.SearchTransportService.messageReceived(SearchTransportService.java:295) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.transport.TransportService.doRun(TransportService.java:610) [elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:596) [elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-5.2.0.jar:5.2.0]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_121]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_121]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]
Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('}' (code 125)): expected a value
 at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@8a49262; line: 1, column: 1111]
    at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1702) ~[jackson-core-2.8.6.jar:2.8.6]
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:558) ~[jackson-core-2.8.6.jar:2.8.6]
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:456) ~[jackson-core-2.8.6.jar:2.8.6]
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2656) ~[jackson-core-2.8.6.jar:2.8.6]
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:832) ~[jackson-core-2.8.6.jar:2.8.6]
    at org.elasticsearch.common.xcontent.json.JsonXContentParser.nextToken(JsonXContentParser.java:55) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.index.query.BoolQueryBuilder.fromXContent(BoolQueryBuilder.java:327) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.search.SearchModule.lambda$registerQuery(SearchModule.java:789) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.common.xcontent.NamedXContentRegistry.parseNamedObject(NamedXContentRegistry.java:162) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.common.xcontent.support.AbstractXContentParser.namedObject(AbstractXContentParser.java:369) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.index.query.QueryParseContext.parseInnerQueryBuilder(QueryParseContext.java:116) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.search.suggest.phrase.PhraseSuggester.innerExecute(PhraseSuggester.java:127) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.search.suggest.phrase.PhraseSuggester.innerExecute(PhraseSuggester.java:58) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.search.suggest.Suggester.execute(Suggester.java:46) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.search.suggest.SuggestPhase.execute(SuggestPhase.java:64) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:94) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.search.SearchService.loadOrExecuteQueryPhase(SearchService.java:246) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:260) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.action.search.SearchTransportService.messageReceived(SearchTransportService.java:298) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.action.search.SearchTransportService.messageReceived(SearchTransportService.java:295) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.transport.TransportService.doRun(TransportService.java:610) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:596) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-5.2.0.jar:5.2.0]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[?:1.8.0_121]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[?:1.8.0_121]
    at java.lang.Thread.run(Thread.java:745) ~[?:1.8.0_121]

你知道我为什么会收到这个错误吗?

你的Mustache模板是错误的,如果你检查你的模板最后写成,\"filter\":{{#toJson}}filters{{/toJson}}}}

toJson 不是标准的 Mustache 功能。它仅在 Elasticsearch 版本 5.0.0 中添加了此 commit,它添加了将 Map 解析为 JSON 对象而不是字符串。此提交仅在 _search/template 端点启用此解析。

如您所见,Phrase Suggester 使用的 Template Query 在 5.0.0 版本中已弃用,建议使用 Search Template API.