lucene - does elasticsearch have compound indexes? -


i'm wondering if elasticsearch needs have compound indexes defined priori. compound index, mean mongodb has.

db.collection.ensureindex( { field1: 1, field2: 1, field3: 1 } )

or mysql db has.

create index adhoc_index on mytable(field1, field2, field3);

so data dealing flat (most of csv format). looks following (for completeness).

field1, field2, ..., fieldn

the number of fields arbitrary. 1 dataset may have 10 fields, 20, 1000. convert each row json document looks following.

{  "field1" : "value1",  "field2" : "value2",  ...  "fieldn" : "valuen" } 

denote a, b, , c 3 mutually exclusive subsets of fields: {field1, field2, ..., fieldn}. @ given time, have build dynamic query filters records a=a, b=b, , c=c.

for example,

  • a = {field1}, b = {field2, field3}, c = {field6}
  • a = {field2}, b = {field1}, c = {field1000, field50}

so elasticsearch dsl query may following (not sure if correct myself, illustrate).

"bool" : {  "must" : [   {"term" : { "field1" : "val1" },   {"term" : { "field2" : "val2" },   {"term" : { "field3" : "val3" },   {"term" : { "field4" : "val4" }  ] } 

basically, query says, "give me documents field1=val1, field2=val2, field3=val3, field4=val4".

the reason why ask elasticsearch because not find clear answer searching on internet compound indexes. needed?

i'm evaluating mongodb , mysql well, , don't think work situation because these compound/composite indexes have defined priori, , won't have information until runtime group of fields need indexed optimize query speed. of course, mysql, once find out group of fields need indexed (and in order), can go create index, may take long time if dataset large (number of rows > 1 million).

do compound index feature out of box elastic search? meaning, won't have touch index mapping file/definition?

elasticsearch doesn't have composite indexes, it's efficient @ querying multiple indexes , intersecting them (intersecting bit-vectors ftw).

most of time, composite indexes not needed, cases mentioned query 4 different fields. elasticsearch happily query 4 different indexes , intersect results in efficient manner. in experience performance matches , surpasses of mongodb in similar situations.

if absolutely must have composite index, might consider indexing auxiliary field value composite of values want index.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -