在建议阶段使用内嵌的collate查询时,使用弹性搜索I/O异常。

时间:2021-02-13 00:46:17

I have a collate query within a phrase_suggestion query in ES 5.2. In order to do that, my collate query is an inline mustache template. However, I'm getting an I/O exception error telling me that there's an unexpected '}' character when I'm passing a filter object to my query with the toJson mustache tag.

我在ES 5.2中的phrase_suggestion查询中有一个collate查询。为了做到这一点,我的collate查询是一个内置mustache模板。但是,我得到了一个I/O异常错误,告诉我当我用toJson mustache标记将一个过滤器对象传递给我的查询时,会出现一个意外的“}”字符。

What's surprising is that my query template seem to be OK when I use the _search/template endpoint. I don't get any error trough this way.

令人惊讶的是,当我使用_search/template端点时,我的查询模板似乎还可以。我不会用这种方法得到任何错误。

Here is my query :

以下是我的提问:

{
    "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
                    }
                }
            }
        }
    }
}

Here is the error log I'm getting in 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$6.messageReceived(SearchTransportService.java:298) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.action.search.SearchTransportService$6.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$7.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$8(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$6.messageReceived(SearchTransportService.java:298) ~[elasticsearch-5.2.0.jar:5.2.0]
    at org.elasticsearch.action.search.SearchTransportService$6.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$7.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]

Do you have any idea why I'm getting this error ?

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

1 个解决方案

#1


1  

Your Mustache template is wrong, if you check your template it is written as ,\"filter\":{{#toJson}}filters{{/toJson}}}} in the end.

您的Mustache模板是错误的,如果您检查您的模板,它将被写为,\“filter\”:{{# json} {}} {} {}} {{}} {} {}} {{}} {} {} {}} {{}} {}} {{}} {{}} {} {} {}} {}} {}} {{}} {}} {}} {

toJson is not standard Mustache functionality. It was added only in Elasticsearch version 5.0.0 with this commit, which added the parsing of Map as JSON object not as a string. This commit only enables this parsing in _search/template endpoint.

toJson不是标准的Mustache功能。在这个commit中,它只添加到flex搜索版本5.0.0中,它添加了对Map作为JSON对象的解析,而不是作为字符串。这个commit只允许在_search/template端点中进行解析。

As you can see Template Query which is used by Phrase Suggester is deprecated in version 5.0.0 and it is advised to use Search Template API.

正如您所看到的,在5.0.0版本中,短语建议者使用的模板查询被弃用,建议使用搜索模板API。

#1


1  

Your Mustache template is wrong, if you check your template it is written as ,\"filter\":{{#toJson}}filters{{/toJson}}}} in the end.

您的Mustache模板是错误的,如果您检查您的模板,它将被写为,\“filter\”:{{# json} {}} {} {}} {{}} {} {}} {{}} {} {} {}} {{}} {}} {{}} {{}} {} {} {}} {}} {}} {{}} {}} {}} {

toJson is not standard Mustache functionality. It was added only in Elasticsearch version 5.0.0 with this commit, which added the parsing of Map as JSON object not as a string. This commit only enables this parsing in _search/template endpoint.

toJson不是标准的Mustache功能。在这个commit中,它只添加到flex搜索版本5.0.0中,它添加了对Map作为JSON对象的解析,而不是作为字符串。这个commit只允许在_search/template端点中进行解析。

As you can see Template Query which is used by Phrase Suggester is deprecated in version 5.0.0 and it is advised to use Search Template API.

正如您所看到的,在5.0.0版本中,短语建议者使用的模板查询被弃用,建议使用搜索模板API。