2016-02-12 70 views
0

我相信是许多使用弹性搜索的用例。这里是我的模板弹性搜索与英文分析器匹配的确切字符串

PUT _template/test 
{ 
    "template" : "test*", 
    "settings" : { 
     "number_of_shards" : 5, 
     "number_of_replicas" : 1 
    }, 
    "mappings" : { 
     "test": { 
     "properties": { 
      "name": { 
      "type": "string", 
      "index": "analyzed" 
      }, 
     "description": { 
      "type": "string", 
      "index": "analyzed", 
      "analyzer":"english", 
      "fields": { 
       "raw": { 
       "type": "string", 
       "index": "not_analyzed" 
       } 
      } 
      } 
     } 
     } 
    } 
} 

现在我打算把单条记录在索引

POST /test/test 
{ 
    "name":"test-1", 
    "description":"on the first day of christmas my true love gave to me a partridge in a pear tree" 
} 

现在想象一下,我有这些记录一百万。我想要做的是,如果我在描述字段上搜索on the,我不想回来,因为这些是英语分析器应该处理的常见词汇。但是,如果我搜索确切的文字"on the",那么我希望返回的文档与确切的文字相匹配。

我对弹性社区的问题是如何允许这个以及查询应该是什么样子?我添加了描述的.raw字段,但不管我的查询字符串是什么,我都无法得到确切的文本来返回任何结果。

+0

你要查询像GET /测试/测试/ _search'{ “查询”:{ “术语”:{ “description.raw”: “上的” } }}' – Richa

+0

当我运行的确切查询我得到'{ “花”:1, “TIMED_OUT”:假的, “_shards”:{ “总”:5, “成功”:5, “失败”:0 }, “命中”:{ “总”:0, “MAX_SCORE”:空, “点击”:[] } }' –

+0

这可能是因为你没有任何说明与确切的文本 – Richa

回答

0

你的第一个要求已经被英文分析仪满足了。现在来解决第二个问题,如果“通过”,你想获得完整匹配的文件。在第二个问题的情况下,应该在“description。raw”字段中进行搜索。将您的字段标记为“原始”:{ “type”:“string”, “index”:“analysed” }此处默认分析器是标准的,因此您将获得整个文档的“on”或“the”或“在”匹配,但如果你想匹配包含确切文件“对”字配置新的自定义分析仪‘’使用领域‘边缘NGRAM’标记者description.raw。 更多细节可以在下面的链接中找到 https://www.elastic.co/guide/en/elasticsearch/guide/current/_index_time_search_as_you_type.html

相关问题