0

尽管我确实有一个应该与查询匹配的文档,但搜索不会返回任何结果。

我确实根据https://github.com/elasticsearch/elasticsearch-mapper-attachments安装了 ElasticSearch mapper-attachments 插件。我也用谷歌搜索了这个主题,并在堆栈溢出中浏览了类似的问题,但还没有找到答案。

这是我在 Windows 7 命令提示符中输入的内容:

c:\Java\elasticsearch-1.3.4>curl -XDELETE localhost:9200/tce
{"acknowledged":true}

c:\Java\elasticsearch-1.3.4>curl -XPUT localhost:9200/tce
{"acknowledged":true}

c:\Java\elasticsearch-1.3.4>curl -XPUT localhost:9200/tce/contact/_mapping -d{\"
contact\":{\"properties\":{\"my_attachment\":{\"type\":\"attachment\"}}}}
{"acknowledged":true}

c:\Java\elasticsearch-1.3.4>curl -XPUT localhost:9200/tce/contact/1 -d{\"my_atta
chment\":\"SGVsbG8=\"}
{"_index":"tce","_type":"contact","_id":"1","_version":1,"created":true}

c:\Java\elasticsearch-1.3.4>curl localhost:9200/tce/contact/_search?pretty
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "tce",
      "_type" : "contact",
      "_id" : "1",
      "_score" : 1.0,
      "_source":{"my_attachment":"SGVsbG8="}
    } ]
  }
}

c:\Java\elasticsearch-1.3.4>curl localhost:9200/tce/contact/_search?pretty -d{\"
query\":{\"term\":{\"my_attachment\":\"Hello\"}}}
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

请注意,“Hello”的 base64 编码值为“SGVsbG8=”,这是我在文档的“my_attachment”字段中插入的值。

我假设 mapper-attachments 插件已正确部署,因为执行上面的映射命令时没有出错。

任何帮助将不胜感激。

4

1 回答 1

0

什么分析仪在my_attachment现场运行?

如果它是标准分析器(看不到任何列出的),那么Hello文本中的 将在索引中变为小写。

即在进行术语搜索时(没有分析器) - 尝试搜索hello

 curl localhost:9200/tce/contact/_search?pretty -d'
     {"query":
       {"term":
         {"my_attachment":"hello"
      }}}'

您还可以查看索引中添加了哪些术语:

curl 'http://localhost:9200/tce/contact/_search?pretty=true' -d '{
   "query" : {
      "match_all" : { }
   },
   "script_fields": {
      "terms" : {
        "script": "doc[field].values",
        "params": {
            "field": "my_attachment"
         }
       }
    }
 }'
于 2014-11-05T09:07:10.127 回答