弹性搜索(DSL):术语不匹配任何内容
Elastic search (DSL): term does not match anything
我是 ES 的新手,我想做一个简单的查询来获取一个域的所有匹配值,但它没有 return 任何东西。 match_all 查询 returns:
curl -XGET localhost:9200/zone/20161201/_search -d '{"query": { "match_all": { }}}'
{"took":4,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":8,"max_score":1.0,"hits":[{"_index":"zone","_type":"20161201","_id":"AVkZ3-ic6lL49IXWU8TZ","_score":1.0,"_source":{"name":"domain2.com"}},{"_index":"zone","_type":"20161201","_id":"AVkZ3-ic6lL49IXWU8Ta","_score":1.0,"_source":{"name":"domain3.com"}},{"_index":"zone","_type":"20161201","_id":"AVkZ4AAQ6lL49IXWU8Te","_score":1.0,"_source":{"name":"domain3.com"}},{"_index":"zone","_type":"20161201","_id":"AVkZ3-ic6lL49IXWU8Tb","_score":1.0,"_source":{"name":"domain4.com"}},{"_index":"zone","_type":"20161201","_id":"AVkZ4AAQ6lL49IXWU8Tc","_score":1.0,"_source":{"name":"domain1.com"}},{"_index":"zone","_type":"20161201","_id":"AVkZ4AAQ6lL49IXWU8Td","_score":1.0,"_source":{"name":"domain2.com"}},{"_index":"zone","_type":"20161201","_id":"AVkZ4AAQ6lL49IXWU8Tf","_score":1.0,"_source":{"name":"domain4.com"}},{"_index":"zone","_type":"20161201","_id":"AVkZ3-ic6lL49IXWU8TY","_score":1.0,"_source":{"name":"domain1.com"}}]}}
但是当我想搜索一个特定值时,它找不到任何东西:
curl -XGET localhost:9200/zone/20161201/_search -d '{"query":{"term":{"name":"domain3.com"}}}'
你能帮帮我吗?这有什么问题吗?
由于我还不能添加评论,我需要创建一个完整的答案来帮助你。
您的类型有哪些映射?术语查询用于未分析字段和仅return完全匹配。
请查看文档了解更多详情。特别是在“为什么词条查询与我的文档不匹配?”部分“=11=]
https://www.elastic.co/guide/en/elasticsearch/reference/2.3/query-dsl-term-query.html
尝试下一个查询:
GET zone/20161201/_search
{
"query": {
"match": {
"name": "domain3.com"
}
}
}
它会起作用的。
现在尝试下一个索引和查询:
POST zone/20161201/
{
"name":"domain.com"
}
注意 我们索引域,没有编号。
然后尝试查询:
GET zone/20161201/_search
{
"query": {
"term": {
"name": "domain.com"
}
}
}
此查询也有效。
当你用 "domain3" 这样的字符串索引字符串时,elastic 将它索引为 [domain,3](默认分析器),然后如果你使用术语查询,elastic 会查看确切的术语,所以他会查看"domain3" 但未找到,因为弹性索引它作为域和 3。
所以更好的方法是使用匹配查询。如果您确切地知道自己在做什么,则可以使用术语查询。
我是 ES 的新手,我想做一个简单的查询来获取一个域的所有匹配值,但它没有 return 任何东西。 match_all 查询 returns:
curl -XGET localhost:9200/zone/20161201/_search -d '{"query": { "match_all": { }}}'
{"took":4,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":8,"max_score":1.0,"hits":[{"_index":"zone","_type":"20161201","_id":"AVkZ3-ic6lL49IXWU8TZ","_score":1.0,"_source":{"name":"domain2.com"}},{"_index":"zone","_type":"20161201","_id":"AVkZ3-ic6lL49IXWU8Ta","_score":1.0,"_source":{"name":"domain3.com"}},{"_index":"zone","_type":"20161201","_id":"AVkZ4AAQ6lL49IXWU8Te","_score":1.0,"_source":{"name":"domain3.com"}},{"_index":"zone","_type":"20161201","_id":"AVkZ3-ic6lL49IXWU8Tb","_score":1.0,"_source":{"name":"domain4.com"}},{"_index":"zone","_type":"20161201","_id":"AVkZ4AAQ6lL49IXWU8Tc","_score":1.0,"_source":{"name":"domain1.com"}},{"_index":"zone","_type":"20161201","_id":"AVkZ4AAQ6lL49IXWU8Td","_score":1.0,"_source":{"name":"domain2.com"}},{"_index":"zone","_type":"20161201","_id":"AVkZ4AAQ6lL49IXWU8Tf","_score":1.0,"_source":{"name":"domain4.com"}},{"_index":"zone","_type":"20161201","_id":"AVkZ3-ic6lL49IXWU8TY","_score":1.0,"_source":{"name":"domain1.com"}}]}}
但是当我想搜索一个特定值时,它找不到任何东西:
curl -XGET localhost:9200/zone/20161201/_search -d '{"query":{"term":{"name":"domain3.com"}}}'
你能帮帮我吗?这有什么问题吗?
由于我还不能添加评论,我需要创建一个完整的答案来帮助你。
您的类型有哪些映射?术语查询用于未分析字段和仅return完全匹配。
请查看文档了解更多详情。特别是在“为什么词条查询与我的文档不匹配?”部分“=11=]
https://www.elastic.co/guide/en/elasticsearch/reference/2.3/query-dsl-term-query.html
尝试下一个查询:
GET zone/20161201/_search
{
"query": {
"match": {
"name": "domain3.com"
}
}
}
它会起作用的。 现在尝试下一个索引和查询:
POST zone/20161201/
{
"name":"domain.com"
}
注意 我们索引域,没有编号。
然后尝试查询:
GET zone/20161201/_search
{
"query": {
"term": {
"name": "domain.com"
}
}
}
此查询也有效。
当你用 "domain3" 这样的字符串索引字符串时,elastic 将它索引为 [domain,3](默认分析器),然后如果你使用术语查询,elastic 会查看确切的术语,所以他会查看"domain3" 但未找到,因为弹性索引它作为域和 3。 所以更好的方法是使用匹配查询。如果您确切地知道自己在做什么,则可以使用术语查询。