Hope it helps... Note, that scripting is of course not that fast, as if you
had stored a field, which only contains the first letter...
For more information, check out the 'Term scripts' part at
--Alex
On Thu, Mar 28, 2013 at 9:27 AM, Maaz Bin Tariq maaz786@gmail.com wrote:
Hi,
I have name field in my documents and I want to get facets on the base of
alphabets (first letter) instead of full name.
just a small, but important note on my sample. I ran this on an analyzed
field, which you should not do. Make sure you run this on a not_analyzed
field, otherwise your facet will return values for each term.
--Alex
On Thu, Mar 28, 2013 at 9:49 AM, Alexander Reelsen alr@spinscale.de wrote:
Hey there,
you can use a term facet with scripting, sample:
curl -X PUT localhost:9200/test/test/1 -d '{ "name":"Alex" }'
curl -X PUT localhost:9200/test/test/2 -d '{ "name":"Berta" }'
curl -X PUT localhost:9200/test/test/3 -d '{ "name":"Caesar" }'
curl -X PUT localhost:9200/test/test/4 -d '{ "name":"Andre" }'
While this might work, it's always more efficient to prepare your data
according to your needs, rather than trying to bolt things on
afterwards. It'll perform better and use less memory.
So if you want to sort on the first letter of a field, then index the
first letter into a different field.
You could even use multi-fields for this, eg the "name" field is
analyzed per usual, and the "name.first_letter" just indexes the first
letter of the name.
Create an index using the pattern tokenizer to capture just
the first letter of each name string
the main "name" field uses the default analyzer, and the
"name.first_letter" field uses our custom analyzer
While this might work, it's always more efficient to prepare your data
according to your needs, rather than trying to bolt things on
afterwards. It'll perform better and use less memory.
So if you want to sort on the first letter of a field, then index the
first letter into a different field.
You could even use multi-fields for this, eg the "name" field is
analyzed per usual, and the "name.first_letter" just indexes the first
letter of the name.
Create an index using the pattern tokenizer to capture just
the first letter of each name string
the main "name" field uses the default analyzer, and the
"name.first_letter" field uses our custom analyzer
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.