0

I have the following document in Elasticsearch as reported by Kibana:

{"deviceId":"C1976429369BFE063ED8B3409DB7C7E7D87196D9","appId":"DisneyDigitalBooks.PlanesAdventureAlbum","ostype":"iOS"}

Why the following query does not return success?

[root@myvm elasticsearch-1.0.0]# curl -XGET 'http://localhost:9200/unique_app_install/_search?pretty=1' -d '
{
  "query" : {
    "bool" : {
      "must" : [ {
        "term" : {
          "deviceId" : "C1976429369BFE063ED8B3409DB7C7E7D87196D9"
        }
      }, {
        "term" : {
          "appId" : "DisneyDigitalBooks.PlanesAdventureAlbum"
        }
      }, {
        "term" : {
          "ostype" : "iOS"
        }
      } ]
    }
  }
}'

Here is the response from Elasticsearch:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

As a side question, is this the fastest way to query the data in my case?

Thx in advance.

UPDATE: Could it be related to the fact that I used the following mapping for this index?

curl -XPOST localhost:9200/unique_app_install -d '{
    "settings" : {
        "number_of_shards" : 5
    },
    "mappings" : {
        "sdk_sync" : {
            "properties" : {
                "deviceId" : { "type" : "string" , "index": "not_analyzed"},
                "appId" : { "type" : "string" , "index": "not_analyzed"},
                "ostype" : { "type" : "string" , "index": "not_analyzed"}
            }
        }
    }
}'
2
  • Are you looking in the correct index? Commented Mar 6, 2014 at 10:51
  • Yes, unique_app_install is the index. Commented Mar 6, 2014 at 11:08

2 Answers 2

1

Check if the type of your document was right while inserting: sdk_sync.

I have used your items and for me it works. Using the following curl request give the right response for me:

curl -XPOST localhost:9200/unique_app_install/sdk_sync/1 -d '{
    "settings" : {
        "number_of_shards" : 5
    },
    "mappings" : {
        "sdk_sync" : {
            "properties" : {
                "deviceId" : { "type" : "string" , "index": "not_analyzed"},
                "appId" : { "type" : "string" , "index": "not_analyzed"},
                "ostype" : { "type" : "string" , "index": "not_analyzed"}
            }
        }
    }
}'

curl -XPOST localhost:9200/unique_app_install/sdk_sync/1 -d '{
    "deviceId":"C1976429369BFE063ED8B3409DB7C7E7D87196D9",
    "appId":"DisneyDigitalBooks.PlanesAdventureAlbum",
    "ostype":"iOS"
}'

curl -XGET 'http://localhost:9200/unique_app_install/_search?pretty=1' -d '
{
  "query" : {
    "bool" : {
      "must" : [ {
        "term" : {
          "deviceId" : "C1976429369BFE063ED8B3409DB7C7E7D87196D9"
        }
      }, {
        "term" : {
          "appId" : "DisneyDigitalBooks.PlanesAdventureAlbum"
        }
      }, {
        "term" : {
          "ostype" : "iOS"
        }
      } ]
    }
  }
}'
Sign up to request clarification or add additional context in comments.

2 Comments

Thx, I think you are right, i might have missed the correct type name, I'll recheck that and let you know.
Thx that was the reason.
0

Unless you specify the field NOT to be analyzed, every fields are analyzed by default.

It means that deviceId "C1976429369BFE063ED8B3409DB7C7E7D87196D9" will be indexed as "c1976429369bfe063ed8b3409db7c7e7d87196d9" (lower case).

You have to use term query or term filter with string in LOWER CASE.

That is the reason why you should specify {"index": "not_analyzed"} for the mapping.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.