根据elasticsearch网站的教程和官方文档,我做了以下两次搜索,但我得到的结果更像是一个contains结果,而不是一个完全匹配的结果。我是个新手,所以请原谅我的错误。任何帮助都将不胜感激。
根据我到目前为止看过的教程,他们的结果并非如此。所以我很困惑为什么我会得到这样的结果。
数据结构:
{
"_scroll_id": "cXVlcnlBbmRGZXRjaDsxOzI3OlRsWmVmMGh5VENLR0FVclB3eXpIaVE7MDs=",
"took": 7,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 16896,
"max_score": 1,
"hits": [
{
"_index": "cus_index",
"_type": "place",
"_id": "71272349",
"_score": 1,
"_source": {
"id": 34543,
"date1": "1928-09-13 00:00:00",
"date2": "1929-01-01 00:00:00",
"code": "1000",
"phrase": "GOD MODE",
"boolCol": false
}
},
{
"_index": "cus_index",
"_type": "place",
"_id": "71272349",
"_score": 1,
"_source": {
"id": 78635,
"date1": "1928-09-13 00:00:00",
"date2": "1929-01-01 00:00:00",
"code": "3000",
"phrase": "THANK GOD",
"boolCol": false
}
},
{
"_index": "cus_index",
"_type": "place",
"_id": "71272349",
"_score": 1,
"_source": {
"id": 45645,
"date1": "1928-09-13 00:00:00",
"date2": "1929-01-01 00:00:00",
"code": "5000",
"phrase": "SOME OTHER GOD PHRASE",
"boolCol": false
}
},
]
}
}
查询:
// returns all rows
{
"query" : {
"constant_score" : {
"filter" : {
"match" : {
"phrase": "GOD MODE"
}
}
}
}
}
// this returns all rows
{
"query" : {
"query_string": {
"query": "GOD MODE",
"fields": ["phrase"]
}
}
}
// this returns no rows
{
"query" : {
"term": {
"phrase": "GOD MODE"
}
}
}
Map:
{
"cus_index": {
"aliases": {},
"mappings": {
"place": {
"properties": {
"id": {
"type": "int"
},
"date1": {
"type": "date"
},
"date2": {
"type": "date"
},
"code": {
"type": "string"
},
// this is the important one
// i just guessed the others as this is an example, But the col in qu is a string
"phrase": {
"type": "string"
},
"boolCol": {
"type": "boolean"
}
}
}
},
"settings": {
"index": {
"creation_date": "1545321229864",
"number_of_shards": "1",
"number_of_replicas": "0",
"uuid": "4PpzZ49SQZWDDW8sawOIaA",
"version": {
"created": "2030199"
}
}
},
"warmers": {}
}
}
es版本:
{
"name": "Test Node",
"cluster_name": "firsttestnode",
"version": {
// this was a very old version latest "6.5.4" this is what i
// should have been using for the answers below to work.
"number": "2.3.1",
"build_hash": "bd980929010aef404e7cb0843e61d0665269fc39",
"build_timestamp": "2016-04-04T12:25:05Z",
"build_snapshot": false,
"lucene_version": "5.5.0"
},
"tagline": "Test tag line"
}
4条答案
按热度按时间bvpmtnay1#
这个
term
查询查找包含倒排索引中指定的确切术语的文档。热释光;博士:
例子:
以上返回结果
以上不返回结果
你甚至可以用
_analyze
```GET test_index1/_analyze
{
"field": "phrase",
"text": ["GOOD GOD"]
}
von4xj4u2#
我在下面给定的url中放置并发布到以下正文,并出现以下错误:
下面的两个答案都如预期的那样有效。多亏了这两个。我不确定答案是否正确,但对于其他阅读本文的人,我建议两者兼而有之。
唯一的问题是在答案1中,'“type”:“string”'应该是'“type”:“text”',这样示例才能正常工作。
axr492tv3#
我建议更新短语属性如下:
在上述情况下,在索引文档时,只需将值传递给
phrase
现场和phrase.keyword
获取自动索引。无论何时要进行精确匹配,都可以使用术语查询,如下所示:
oiopk7p54#
--回答尝试