我在搜索索引时遇到问题。这是我的索引创建:
curl -XPUT localhost:9200/my_supder_index -d '{
"mappings":
{
"doctype_I_index":
{
"properties":
{
"field_I_index":
{
"type":"string",
"term_vector":"yes"
}
}
}
}
}'
这是该索引中的示例内容:
{
_index:"my_super_index",
_type:"doctype_I_index",
_id:"676078",
_version:1,
found:true,
_source:{
created:"2015-05-02T00:24:03",
field_I_index:[
"21E0",
"19E0",
"5E0",
"6E0",
"4E0"
],
id:676078
}
}
现在,当我这样搜索时:
curl -XGET 'http://127.0.0.1:9200/my_super_index/_search' -d '{
"sort":[
{
"created":{
"order":"desc"
}
}
],
"query":{
"bool":{
"must":[
{
"terms":{
"field_I_index":[
"21E0"
],
"minimum_should_match":1
}
}
]
}
}
}'
我得到零结果。它不在文本上进行匹配。谁能指出我正确的方向?
最佳答案
在检查此值的分析方式时,结果如下:
curl -XPOST 'localhost:9200/news/_analyze?pretty' -d '21E0'
{
"tokens" : [ {
"token" : "21e0",
"start_offset" : 0,
"end_offset" : 4,
"type" : "<ALPHANUM>",
"position" : 1
} ]
}
在这里您可以看到文本是小写的。
另外,由于term query不适用于搜索文本,所以它查找21E0的精确匹配项,但21e0才被索引。
因此,在这种情况下,如果您使用match query而不是术语query,它应该可以工作。
但是我建议对字段使用not_analyzed,然后在其上使用术语查询。这可能是一个更好的方法。
关于json - Elasticsearch搜索字符串类型的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30038797/