2015-11-05 73 views
0

所以我下面的语句建议者模板:Elasticsearch短语建议者整理返回false即使查询结果带来回

PUT /_search/template/DidYouMean 
{ 
    "template": { 
    "size": 0, 
    "suggest": { 
     "DidYouMean": { 
     "text": "{{SearchPhrase}}", 
     "phrase": { 
      "field": "_all", 
      "analyzer": "simple", 
      "size": 50, 
      "real_word_error_likelihood": 0.9, 
      "max_errors": 0.5, 
      "gram_size": 3, 
      "direct_generator": [ 
      { 
       "field": "_all", 
       "suggest_mode": "always", 
       "min_word_length": 3 
      } 
      ], 
      "collate": { 
      "prune": true, 
      "query": { 
       "match": { 
       "_all": { 
        "query": "{{suggestion}}" 
       } 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
} 

我使用此查询运行它:

POST /my_index/_search/template 
{ 
    "template": { 
    "id": "DidYouMean" 
    }, 
    "params": { 
    "SearchPhrase": "unileve" 
    } 
} 

而且我很期待以"collate_match": true作为结果获得联合利华(一家公司),但是,它将带回false。我得到这个,虽然我很期待联合利华来与真:

{ 
    "took": 25, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 220692, 
     "max_score": 0, 
     "hits": [] 
    }, 
    "suggest": { 
     "DidYouMean": [ 
     { 
      "text": "unileve", 
      "offset": 0, 
      "length": 7, 
      "options": [ 
       { 
        "text": "unilever", 
        "score": 0.016954133, 
        "collate_match": false 
       }, 
       { 
        "text": "unilevers", 
        "score": 0.005391976, 
        "collate_match": false 
       }, 
       { 
        "text": "unilet", 
        "score": 0.00062763924, 
        "collate_match": false 
       }, 
       { 
        "text": "uniline", 
        "score": 0.00062518474, 
        "collate_match": false 
       }, 
       { 
        "text": "unilerver", 
        "score": 0.00055350363, 
        "collate_match": false 
       }, 
       { 
        "text": "uniliver", 
        "score": 0.00055350363, 
        "collate_match": false 
       }, 
       { 
        "text": "unielever", 
        "score": 0.0005243993, 
        "collate_match": false 
       } 
      ] 
     } 
     ] 
    } 
} 

现在,当我自己运行相同的查询,它带来的结果返回。

POST /my_index/_search 
{ 
    "query": { 
    "match": { 
     "_all": { 
     "query": "unilever" 
     } 
    } 
    } 
} 

它确实带来了结果。

{ 
    "took": 4, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 4305, 
     "max_score": 3.1709287, 
     "hits": [ 
     { 
      "_index": "my_index", 
      "_type": "companies", 
      "_id": "754743", 
      "_score": 3.1709287, 
      "_source": { 
       "CompanyName": "Unilever Iran Co" 
      } 
     }, 
     { 
      "_index": "my_index", 
      "_type": "companies", 
      "_id": "751585", 
      "_score": 3.1709287, 
      "_source": { 
       "CompanyName": "Unilever UK Ltd" 
      } 
     }, 
     { 
      "_index": "my_index", 
      "_type": "companies", 
      "_id": "10363", 
      "_score": 3.1709287, 
      "_source": { 
       "CompanyName": "Unilever (Schweiz) AG" 
      } 
     }, 
     { 
      "_index": "my_index", 
      "_type": "companies", 
      "_id": "647311", 
      "_score": 3.1709287, 
      "_source": { 
       "CompanyName": "Unilever Taiwan Ltd" 
      } 
     }, 
     { 
      "_index": "my_index", 
      "_type": "companies", 
      "_id": "651158", 
      "_score": 3.1709287, 
      "_source": { 
       "CompanyName": "Unilever Gulf FZE" 
      } 
     }, 
     { 
      "_index": "my_index", 
      "_type": "companies", 
      "_id": "654498", 
      "_score": 3.1709287, 
      "_source": { 
       "CompanyName": "Unilever China Ltd" 
      } 
     }, 
     { 
      "_index": "my_index", 
      "_type": "companies", 
      "_id": "654664", 
      "_score": 3.1709287, 
      "_source": { 
       "CompanyName": "Unilever NV" 
      } 
     }, 
     { 
      "_index": "my_index", 
      "_type": "companies", 
      "_id": "650307", 
      "_score": 3.1709287, 
      "_source": { 
       "CompanyName": "Unilever Canada Ltd" 
      } 
     }, 
     { 
      "_index": "my_index", 
      "_type": "companies", 
      "_id": "710125", 
      "_score": 3.1709287, 
      "_source": { 
       "CompanyName": "Unilever Ltd" 
      } 
     }, 
     { 
      "_index": "my_index", 
      "_type": "companies", 
      "_id": "722327", 
      "_score": 3.1709287, 
      "_source": { 
       "CompanyName": "Unilever Croatia" 
      } 
     } 
     ] 
    } 
} 

我是否误解了整理的目的?或者我只是在做一些完全错误的事情。请指教。

Elasticsearch版本:1.7.3

回答

0

我能够自己解决这个问题。

问题:

  1. 我是创建一个模板。
    • {{suggestion}}预期作为参数,但未提供
    • 所以我的理解,它的渲染,没有它搭配查询是针对没有运行

我怎么修复它?

查询模板需要以某种方式呈现{{suggestion}},所以我不得不逃避这些角色。看到这个:

PUT /_search/template/DidYouMean 
{ 
    "template": { 
    "size": 0, 
    "suggest": { 
     "DidYouMean": { 
     "text": "{{SearchPhrase}}", 
     "phrase": { 
      "field": "_all", 
      "analyzer": "simple", 
      "size": 50, 
      "real_word_error_likelihood": 0.9, 
      "max_errors": 0.5, 
      "gram_size": 3, 
      "direct_generator": [ 
      { 
       "field": "_all", 
       "suggest_mode": "always", 
       "min_word_length": 3 
      } 
      ], 
      "collate": { 
      "prune": true, 
      "query": { 
       "match": { 
       "_all": { 
        "query": "{{=<% %>=}}{{suggestion}}<%={{ }}=%>" 
       } 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
} 

How does one use a literal {{ in a Mustache template?给出答案是如何做到的。

现在它将此作为参数呈现,而不是期望通过

相关问题