Elasticsearch:搜索具有映射 not_analyzed 的字段没有命中
Elasticsearch: Searching for fields with mapping not_analyzed get no hits
我有 elasticsearch 运行 并使用 nodejs 处理我的所有请求。
我为我的索引应用了以下映射 "mastert4":
{
"mappings": {
"mastert4": {
"properties": {
"s": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
我只在索引中添加了一个文档,它看起来很像这样:
{
"master": {
"vi": "ff155d9696818dde0627e14c79ba5d344c3ef01d",
"s": "Anne Will"
}
}
现在执行以下任何搜索查询都不会 return 任何命中:
{
"index": "mastert4",
"body": {
"query": {
"filtered": {
"query": {
"match"/"term": {
"s": "anne will"/"Anne Will"
}
}
}
}
}
}
但以下查询将 return 确切的文档:
{
"index": "mastert4",
"body": {
"query": {
"filtered": {
"query": {
"constant_score": {
"filter": [
{
"missing": {
"field": "s"
}
}
]
}
}
}
}
}
}
如果我搜索
{
"exists": {
"field": "s"
}
}
我不会再上当了
在分析字段本身时,我得到:
{
"tokens": [
{
"token": "Anne Will",
"start_offset": 0,
"end_offset": 9,
"type": "word",
"position": 1
}
]
}
我真的走投无路了。有人可以告诉我我哪里做错了吗?谢谢!!!!
您已将字段 s
和 vi
包含在名为 master
的外部字段中,该字段未在您的映射中声明。这就是原因。如果您查询 master.s
,您将获得结果。
第二种解决方案是删除文档中封闭的 master
对象,这也适用:
{
"vi": "ff155d9696818dde0627e14c79ba5d344c3ef01d",
"s": "Anne Will"
}
我有 elasticsearch 运行 并使用 nodejs 处理我的所有请求。 我为我的索引应用了以下映射 "mastert4":
{
"mappings": {
"mastert4": {
"properties": {
"s": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
我只在索引中添加了一个文档,它看起来很像这样:
{
"master": {
"vi": "ff155d9696818dde0627e14c79ba5d344c3ef01d",
"s": "Anne Will"
}
}
现在执行以下任何搜索查询都不会 return 任何命中:
{
"index": "mastert4",
"body": {
"query": {
"filtered": {
"query": {
"match"/"term": {
"s": "anne will"/"Anne Will"
}
}
}
}
}
}
但以下查询将 return 确切的文档:
{
"index": "mastert4",
"body": {
"query": {
"filtered": {
"query": {
"constant_score": {
"filter": [
{
"missing": {
"field": "s"
}
}
]
}
}
}
}
}
}
如果我搜索
{
"exists": {
"field": "s"
}
}
我不会再上当了
在分析字段本身时,我得到:
{
"tokens": [
{
"token": "Anne Will",
"start_offset": 0,
"end_offset": 9,
"type": "word",
"position": 1
}
]
}
我真的走投无路了。有人可以告诉我我哪里做错了吗?谢谢!!!!
您已将字段 s
和 vi
包含在名为 master
的外部字段中,该字段未在您的映射中声明。这就是原因。如果您查询 master.s
,您将获得结果。
第二种解决方案是删除文档中封闭的 master
对象,这也适用:
{
"vi": "ff155d9696818dde0627e14c79ba5d344c3ef01d",
"s": "Anne Will"
}