Introdução a Big Data e Apache Solr

Para quem está interessado em Big Data e além disso quer algo prático utilizando Apache Solr, disponibilizo um conjunto de slides que podem ser utilizados por Estudantes, Professores e profissionais. Usem e distribuam a vontade!

Palestra FLISOL na FEMA em Assis – SP / Slides

Pessoal, aqui estão os slides que fiquei de compartilhar da palestra ministrada na FEMA/ASSIS – SP, no evento FLISOL, no ultimo dia 16 de abril. Enjoy!

Gostaria de agradecer a organização pelo convite e parabenizar a todos pela iniciativa e participação. Em tempo de crise, o melhor que temos a fazer é continuar dando duro e compartilhar conhecimento para que todos crescam juntos!

Categorias:Academic Initiative

Utilizando o Startup Order no WebSphere

Muitas vezes vamos fazer o deploy de um novo release de uma aplicação em um servidor de aplicações, e para fazer isso, simplesmente sobrescrevemos a aplicação anterior (update). Isso não é muito interessante do ponto de vista de um rollback. Se você precisar voltar para a antiga versão, pode demorar um pouco mais.

Uma forma interessante para contornar isso é utilizar o Startup Order.

Eu sugiro uma boa prática em nossos processos de deploy: Ao fazer o deploy de um novo release para sua aplicação, você deve dar um nome diferente a ela, por exemplo: “Aplicacao_X_release_2”, e setar o Startup Order (stating weight em versões antigas) para 1, como na figura (screen de versão Antiga do WAX – 7):

Utilizando o Starting Weight no WebSphere

Versão mais recente (8 e 8.5):


Após isso, devemos ir no release anterior, e setar o starting weight/startup order para algo maior que um.

Assim, reiniciamos o servidor de aplicação, e quando ele iniciar, vai levantar a aplicação com o menor peso, pois ao tentar levantar a aplicação com o peso maior, o servidor vai verificar que o context root já está em uso por outra aplicação.

Esta é uma ótima prática para evitarmos operações de rollback demoradas. Se tivermos algum problema no novo release, podemos simplesmente fazer a troca de pesos, ou seja, colocar 1 no release mais antigo e 100 no novo release, assim, reiniciar o servidor de aplicação, e o mesmo, iniciará o antigo release, sem problemas!


Field x Facet

Many people who start to work with Apache Solr or Watson Explorer have the first primary doubt about What is the difference from Field against Facet.

We can simple define that the field represent the indexed data, and the facet its such a GROUP, combined usually by volume. As described at Solr documentation “faceting is the arrangement of search results into categories based on indexed terms”.

Its possible to configure FACETS with many options like sort, searchable, etc. Each product have its possibilities.

Think that when you perform a query, you will use FACETs in the “Where”, something like this:

Select FIELDS from COLLECTION where FACET MY_FACET = ‘dummy’;

This will make you understand better!


Enabling Wildcard in a collection at Watson Explorer

Eventually we need to enable search using wildcards like * for a collection at Watson Explorer. For sure this can make our queries consume more CPU and Memory, you can think comparing a query that perform a “select … where field = ‘XXX'” against a query that perform a “select …. where field like ‘*XXX'” (pseudo code). What will be faster? So, think carefully before enable this!

To enable, go to your collection configuration -> Indexing -> Term expansion support (4)  , and check Generate Dictionaries.


For more information, check here and here.



Finding bottlenecks at Watson Explorer queries

If you are having problem with some Watson Explorer query, an excellent way to find bottlenecks is to perform the query with Debug and Profile options enabled, it will help you to find where exactly you have problems.

Usually, when you perform a query at WEX, you call some URL like the following (in my case port is 7205, MY_COLLECTION can be a shard, for example MY_COLLECTION_1_1):

<SERVER>:<PORT>/search?collection=MY_COLLECTION&query-xml=<%3fxml version%3d”1.0″ encoding%3d”UTF-8″%3f><operator logic%3d”and”%2f>&num=1&max=1&binning-mode=normal&start=0&show-duplicates=1&doc-axl=<%3fxml version%3d”1.0″ encoding%3d”UTF-8″%3f><document key-hash%3d”{vse%3adoc-hash()}”%2f>&binning-config=<%3fxml version%3d”1.0″ encoding%3d”UTF-8″%3f><binning-sets><binning-set bs-id%3d”VENDOR” logic%3d”or” max-bins%3d”8″ select%3d”%24VENDOR”%2f><binning-set bs-id%3d”REVENUE_USD_FACET” logic%3d”or” max-bins%3d”11″ select%3d”%24REVENUE_USD_FACET”%2f>……………field%3d”SERVICE_AREA”><field-to name%3d”SERVICE_AREA”%2f><%2ffield-map><field-map field%3d”MAX_IGS_REV_OM_BRAND_CD”><field-to name%3d”MAX_IGS_REV_OM_BRAND_CD”%2f><%2ffield-map><field-map field%3d”EMAIL_SENT”><field-to name%3d”EMAIL_SENT”%2f><%2ffield-map><field-map field%3d”REVENUE_USD_FACET”><field-to name%3d”REVENUE_USD_FACET”%2f><%2ffield-map><field-map field%3d”REVENUE”><field-to name%3d”REVENUE”%2f><%2ffield-map><field-map field%3d”CLIENT_NAME”><field-to name%3d”CLIENT_NAME”%2f><%2ffield-map><%2ffield-mapping>&sort-keys=1&score=1&shingles=0&summarize=0&gen-key=0&cache-data=0&force-binning=1&output-acls=1

If you don’t have IDEA about HOW to get the query that your Application is doing, you can enable Debug at your collection. Go to WEX console, under Configuration -> Searching -> Debugging and enable Query Logging.


When saved, it will start to generate log in a file called queries.log, under you collection folder, some place like:


You can check it at WEX console, under your collection configuration, tab META, field Filebase.

Ok, now, if you call this URL from your browser, appending “&debug=1&profile=1″ to the URL, you will got a XML file. Download it and lets analyze. For our case, see this:

<xpath-performance xpath=”($FIELD_X) = ‘GBS – No’ or ($FIELD_X) = ‘GBS – Yes'” slow-ms=”10295″ n-slow=”192000″ n-fast=”0″ n-direct=”0″ n-hashes=”1″ />

THIS tell me that JUST in order to get the field FIELD_X, I’m having slow! (I’m my case it is because my Field its an Array)

So, probably I have a problem with this field, that can be a lot, for example:
1- Null values (see my other posts)
2- Its an array to index
3- Its a long text field
4- You have a lot of possible statements using it (OR, AND, WHERE, etc)

With this information, you can go to next step, that is find a way to change the field and make it work better.

Important: I tested this with Watson Explorer 9, 10 and 11. Running at Linux Machines.


Watson Explorer performance decrease with null values

Working with Watson Explorer (WEX) we saw that the search performance decrease a lot when you have null values for some field/facet. (Our WEX release at this moment is 11, we run at Linux machines and our application was written in Java, using BigIndex to index and search. (Also have pure REST version of our application in test and the problem still happen)).

For example: lets suppose that you have a facet called VENDOR in an entity called Product. Suppose that you have 5 millions Products indexed and for some of then you have nulls, in my case 2 Millions have NULL values for VENDOR field.

In this case (and similar ones), we notice a performance decrease in searches. We start to see problems when the relation of null are greater than 20%.

In order to solve the problem we have 2 options:

1- One technique we’ve used for certain dimensions is to always ensure non-null values in the index — so at index time, we either coalesce in our SQL pulls from DB2 or do transformation after ingestion to replace nulls with some predefined value. In our case we use the literal string “(no value available)”.  It: a) ensures non-null values, b) is fairly meaningful to users, and c) gives users a way to actually filter on those records if needed.

2- For some FIELDS, we can not add another values, must leave null (Business reasons) and must not show null option to user select in the facet. In this case, in the moment of search we append boolean($FIELD) to the query. For example:

General example of a slow facet query:
Rewritten query that solve the slowness:
boolean($VENDOR) and ($VENDOR=’IBM or $VENDOR=’PEPSICO’)
This way, it ignore the null values when searching and it will be very fast.
Maybe this is not the final solution and for newer WEX versions it will handle better with null values, but, this was the solution for us.