title: elasticsearch facet limit
body: <p>I am using elasticsearch 0.20.2 on EC2 instance (16GB RAM, no swap enabled). I have a lot indexed documents and when I try to do facet results I got heap space error and elasticsearch server is unusable then. I was increasing heap memory for java but nothing helps. So my question is can I limit number of documents on which facet will be applied.</p>
  
  <p>Here is my settings and mapping:</p>
  
  <pre><code>my_settings = {
      'settings': {
          'analysis': {
              'analyzer': {
                  'text_analyzer': {
                      'tokenizer': 'standard',
                      'filter': ['standard', 'lowercase']
                  },
                  'suggestions_analyzer': {
                      'tokenizer': 'standard',
                      'filter': ['suggestions_shingle']
                  }
              },
              'filter': {
                  'suggestions_shingle': {
                      'type': 'shingle',
                      'min_shingle_size': 2,
                      'max_shingle_size': 5
                  }
              }
          }
      }
  }
  
  my_mapping = {
      'test-type':{
          'properties':{
              'publish_datetime': {'type': 'date'},
              'text': {
                  'type': 'multi_field',
                  'fields': {
                      'text': {'type': 'string', 'analyzer': 'text_analyzer', 'include_in_all': True},
                      'suggestions': {'type': 'string', 'analyzer': 'suggestions_analyzer', 'include_in_all': False}
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>and my search query is:</p>
  
  <pre><code>query = {
      'filtered': {
          'filter' : {
              'limit' : {'value' : 10}
          },
          'query':{
              'prefix':{
                      'text.suggestions': 'wha'
              }
          },
      },
      'facets':{
          'text_suggestions':{
              'terms':{
                  'field':'text.suggestions',
                  'regex':'^%s.*' % 'wha',
                  'size': 5
              }
          }
      },
      'size': 0
  }
  </code></pre>
  
  <p>Is someone succeed to limit document number which will be facet let share with us.</p>