弹性搜索建议过滤器

时间:2015-05-05 06:41:32

标签: elasticsearch full-text-search

我正在使用弹性搜索API实现搜索操作的建议过滤器。

我遇到的问题就像我只能在prefix search进行搜索,但我不能用中间词。

我曾尝试过以下示例:

PUT / bls {
  "mappings": {
    "bl": {
      "properties": {
        "name": {
          "type": "string",
          "index": "not_analyzed"
        },
        "name_suggest": {
          "type": "completion",
          "context": {
            "store": {
              "type": "category"
            },
            "status": {
              "type": "category"
            }
          }
        }
      }
    }
  }
}

 POST / bls / bl / 1 {
   "name": "LG 32LN5110 32 inches LED TV",
   "name_suggest": {
     "input": ["sony 32LN5110 32 inches LED TV"],
     "context": {
       "store": [
         44,
         45
       ],
       "status": "Active"
     }
   }
 }

 POST / bls / _suggest ? pretty {
   "name_suggest": {
     "text": "sony",
     "completion": {
       "field": "name_suggest",
       "context": {
         "store": "44",
         "status": "Active"
       }
     }
   }
 }

我得到了上面的查询结果,但我不能用以下查询进行搜索:

 POST / bls / _suggest ? pretty {
   "name_suggest": {
     "text": "LED",
     "completion": {
       "field": "name_suggest",
       "context": {
         "store": "44",
         "status": "Active"
       }
     }
   }
 }

以上查询显示结果如下:

{
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "name_suggest": [{
    "text": "LED",
    "offset": 0,
    "length": 3,
    "options": []
  }]
}

0 个答案:

没有答案