3

I'm trying to range index only ExpireDate property. I have written the following index. is it correct?

If I make automatic = false, I'm unable to query. However, my concern is that because automatic = true, all properties for all levels are indexed, which I dont want.

{
  "indexingMode": "consistent",
  "automatic": true,
  "includedPaths": [
    {
      "path": "/ExpireDate/?",
      "indexes": [
        {
          "kind": "Range",
          "dataType": "Number",
          "precision": -1
        },
        {
          "kind": "Hash",
          "dataType": "String",
          "precision": 3
        }
      ]
    }
  ],
  "excludedPaths": [
    {
      "path": "/"
    }
  ]
}
Ahmet
  • 906
  • 1
  • 8
  • 22
  • What error do you get when you set it to false? What is the data type of the ExpireDate property? Last I remember, DocDB doesn't support datetime range queries - although that could have changed recently. – Arnab Chakraborty Feb 01 '16 at 23:47
  • I have made them unixdate time. So they are long values actually. – Ahmet Feb 02 '16 at 07:15

1 Answers1

4

If ExpireDate is a number, then this is correct. If it's represented as string e.g. ISO-8601, you'd want to set the index to Range on strings and numbers, i.e. like the stub below. Note that this is configuration

    {
      "path": "/ExpireDate/?",
      "indexes": [
        {
          "kind": "Range",
          "dataType": "Number",
          "precision": -1
        },
        {
          "kind": "Range",
          "dataType": "String",
          "precision": -1
        }
      ]
}

Automatic should be set to true in most cases. It indicates whether documents should be opted-in to indexing by default or not. If this is false, you need to pass in an IndexingDirective.Include explicitly on document write time. If this is set to true, you need to pass in an IndexingDirective.Exclude to exclude a document explicitly. Only the paths covered by the rule above (default everything, in this case ExpireDate) will be indexed regardless of automatic true/false.

Aravind Krishna R.
  • 7,885
  • 27
  • 37