2017-01-16 88 views
0

我使用的elasticsearch版本是es2.2。我输入了与全文搜索官方教程相同的代码。 (https://www.elastic.co/guide/en/elasticsearch/guide/current/match-query.htmlElasticsearch:全文搜索不起作用

看来全文不适合我。我的设置有什么问题?谢谢!
我的代码类型如下:

curl -XDELETE 'localhost:9200/my_index ' 
curl -XPUT 'localhost:9200/my_index ' -d ' 
{ 
"settings": { "number_of_shards": 1 } 
}' 
curl -XPOST 'localhost:9200/my_index/my_type/_bulk' -d' 
{ "index": { "_id": 1 }} 
{ "title": "The quick brown fox" } 
{ "index": { "_id": 2 }} 
{ "title": "The quick brown fox jumps over the lazy dog" } 
{ "index": { "_id": 3 }} 
{ "title": "The quick brown fox jumps over the quick dog" } 
{ "index": { "_id": 4 }} 
{ "title": "Brown fox brown dog" }' 

curl -XGET 'localhost:9200/my_index/my_type/_search' -d' 
{ 
    "query": { 
     "match": { 
      "title": "QUICK!" 
     } 
    } 
}' 

返回的结果为:{ “花”:1, “TIMED_OUT”:假, “_碎片”:{ “总”:1, “成功”:1 ,“失败”:0},“hits”:{“total”:0,“max_score”:null,“hits”:[]}}

当我输入精确查询时,它存储在索引中。

curl -XGET 'localhost:9200/my_index/my_type/_search' -d' 
{ 
    "query": { 
     "match": { 
      "title": "The quick brown fox" 
     } 
    } 
}' 

输出是: { “花”:1, “TIMED_OUT”:假, “_碎片”:{ “总”:1, “成功”:1, “失败”:0}”命中 “:{” 总 “:1,” MAX_SCORE “:1.4054651,” 命中 “:[{” _索引 “:” my_index”, “_类型”: “my_type”, “_ ID”: “1”, “_分数”: 1.4054651, “_源”:{ “标题”: “快速褐色fox”}}]}}

我还测试分析仪:

curl -XGET 'localhost:9200/_analyze' -d' 
{ 
    "analyzer": "standard", 
    "text": "Text to analyze" 
}' 

卷曲:(6)无法解析主机'GET' {“t okens “:[{” 标记 “:” 文本 “ ”start_offset“:0 ”end_offset“:4, ”类型“: ”“, ”位置“:0},{ ”标记“: ”到“,” start_offset “:5”,end_offset “:7,” 类型 “:” “ ”位置“:1},{ ”标记“: ”分析“, ”start_offset“:8中, ”end_offset“:15, ”类型“:” “,”position“:2}]}

这个错误是否影响结果?

+0

那么你执行什么查询会导致“错误”结果? – rednaw

+0

该查询显示在代码中。它是:curl -XGET'localhost:9200/my_index/my_type/_search'-d' { “query”:{ “match”:{ “title”:“QUICK!” } } }' – chocolate9624

+0

您是否尝试搜索“quick”而不是'QUICK!'?另外,最后一次搜索在'curl'命令中有'GET'两次。 – rednaw

回答

0

现在可以!问题是我没有为“标题”索引设置“分析器”。当我设置“分析器”时,全文搜索起作用!我不应该相信默认的分析仪。