0

Search does not return any results although I do have a document that should match the query.

I do have the ElasticSearch mapper-attachments plugin installed per https://github.com/elasticsearch/elasticsearch-mapper-attachments. I have also googled the topic as well as browsed similar questions in stack overflow, but have not found an answer.

Here's what I typed into a windows 7 command prompt:

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" : [ ]
  }
}

Note that the base64 encoded value of "Hello" is "SGVsbG8=", which is the value I have inserted into the "my_attachment" field of the document.

I am assuming that the mapper-attachments plugin has been deployed correctly because I don't get an error executing the mapping command above.

Any help would be greatly appreciated.

1 Answers1

0

What analyzer is running against the my_attachment field?

if it's the standard analyser (can't see any listed) then the Hello in the text will be made lowercase in the index.

i.e. when doing a term search (which doesn't have an analyzer on it) - try searching for hello

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

you can also see which terms have been added to the index:

curl 'http://localhost:9200/tce/contact/_search?pretty=true' -d '{
   "query" : {
      "match_all" : { }
   },
   "script_fields": {
      "terms" : {
        "script": "doc[field].values",
        "params": {
            "field": "my_attachment"
         }
       }
    }
 }'
Olly Cruickshank
  • 6,120
  • 3
  • 33
  • 30
  • I am assuming it's the default analyzer cause I have not made any configuration changes. I also tried searching with "hello", but no luck there - still doesn't return any results. – zorbathegeek Nov 05 '14 at 20:02
  • It does feel like the problem is in the attachment type field. I added another document with two properties with string values and performing a search on them returns the expected results. curl -XPUT http://localhost:9200/tce/contact/3 -d'{" firstName":"John","lastName":"Doe"}' curl localhost:9200/tce/contact/_search?pretty -d{"query":{"term":{"firstName":"john"}}} Returns one document as expected (response abbreviated): ... "hits" : { "total" : 1, ... "hits" : [ { "_id" : "3", "_score" : 0.30685282, "_source":{"firstName":"John","lastName":"Doe"} } ] – zorbathegeek Nov 05 '14 at 20:16
  • Turns out it was a problem with the installation of the plugin. Removed previous installation and reinstalled. Recreated index using above steps and the search returned the right set of results. Regardless, the suggestion to try out with all lowercase keyword was still helpful. Accepting the answer. Thanks! – zorbathegeek Nov 14 '14 at 00:20