Elasticsearch没有提供我期望的输出

时间:2016-02-19 09:28:32

标签: search elasticsearch full-text-search

我的搜索查询是:

query: {
  match: {
    name: "le sul"
  }
},

我希望将输出视为:

.-------------------------------------------------.
|  ID   |            Name             |   Score   |
|-------|-----------------------------|-----------|
| 9     | le sultan                   | ...       |
| 467   | le sultan                   | ...       |
| 23742 | LE DUONG                    | 1.1602057 |
| 11767 | LE VICTORIA                 | 0.9554229 |
| 11758 | LE CANONNIER                | 0.9554229 |
| 23762 | PHA LE XANH                 | 0.9281646 |
| 15795 | LE SURCOUF HOTEL & SPA      | 0.9281646 |
| 33066 | LE CORAL HIDEAWAY BEYOND    | 0.8695703 |
| 11761 | LE MERIDIEN MAURITIUS       | 0.8682439 |
| 11871 | LE RELAX HOTEL & RESTAURANT | 0.8682439 |
'-------------------------------------------------'

但我看到的是:

.-------------------------------------------------.
|  ID   |            Name             |   Score   |
|-------|-----------------------------|-----------|
| 23742 | LE DUONG                    | 1.1602057 |
| 9     | le sultan                   | 1.0869629 | <----
| 11767 | LE VICTORIA                 | 0.9554229 |
| 11758 | LE CANONNIER                | 0.9554229 |
| 467   | le sultan                   | 0.9554229 | <----
| 23762 | PHA LE XANH                 | 0.9281646 |
| 15795 | LE SURCOUF HOTEL & SPA      | 0.9281646 |
| 33066 | LE CORAL HIDEAWAY BEYOND    | 0.8695703 |
| 11761 | LE MERIDIEN MAURITIUS       | 0.8682439 |
| 11871 | LE RELAX HOTEL & RESTAURANT | 0.8682439 |
'-------------------------------------------------'

如你所见,&#34; le sul tan&#34;不是结果集的第一个元素。

我哪里错了?

2 个答案:

答案 0 :(得分:2)

Your query result is not match because elasticsearch search via _score.

In your case you want to search in an analyzed search and get result in not analyzed.

So you should put your mapping like given  below 


Put your_index_name
{
   "mappings": {
      "your_type_name": {
           "properties": {
         "name": {
            "type": "string",
            "analyzer": "english",
            "fields": {
               "your_temporary_sort_filed_name": {
                  "type": "string",
                  "index": "not_analyzed"
               }
            }
         }
      }
    }
   }
}

And then

GET /your_index_name/your_type_name/_search
{
  "sort": [
     {
        "name.your_temporary_sort_filed_name":{
            "order": "desc"
        }
     }
  ], 
    "query": {
        "match": {
           "name": "le sul"
        }
    }
}

答案 1 :(得分:1)

如果您希望le sultan使用以下查询:

{

"query": {
  "query_string": {
     "default_field": "name",
      "query": "le sul*"
     }
   }
}