Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Elasticsearch Symfony2 integration, data struct...

Elasticsearch Symfony2 integration, data structures

Oleg Zinchenko

May 31, 2013
Tweet

More Decks by Oleg Zinchenko

Other Decks in Technology

Transcript

  1. Indexes B-Tree Spatial grid Quadtree R-Tree Hash Bitmap Reverse index

    Inverted index Partial index Function-based index http://habrahabr.ru/post/102785/
  2. Inverted index "it is what it is" -- 0 "what

    is it" -- 1 "it is a banana" -- 2
  3. Inverted index "it is what it is" -- 0 "what

    is it" -- 1 "it is a banana" -- 2 "a": {2} "banana": {2} "is": {0, 1, 2} "it": {0, 1, 2} "what": {0, 1}
  4. Inverted index "it is what it is" -- 0 "what

    is it" -- 1 "it is a banana" -- 2 "a": {2} "banana": {2} "is": {0, 1, 2} "it": {0, 1, 2} "what": {0, 1} "what is it"
  5. Inverted index "it is what it is" -- 0 "what

    is it" -- 1 "it is a banana" -- 2 "a": {2} "banana": {2} "is": {0, 1, 2} "it": {0, 1, 2} "what": {0, 1} "what is it" "what" "is" "it"
  6. Inverted index "it is what it is" -- 0 "what

    is it" -- 1 "it is a banana" -- 2 "a": {2} "banana": {2} "is": {0, 1, 2} "it": {0, 1, 2} "what": {0, 1} "what is it" "what" "is" "it"
  7. Inverted index "it is what it is" -- 0 "what

    is it" -- 1 "it is a banana" -- 2 "a": {2} "banana": {2} "is": {0, 1, 2} "it": {0, 1, 2} "what": {0, 1} "what is it" "what" "is" "it" {0,1} ⋂ {0,1,2} ⋂ {0,1,2} = {0,1}
  8. Inverted index "it is what it is" -- 0 "what

    is it" -- 1 "it is a banana" -- 2 "a": {2} "banana": {2} "is": {0, 1, 2} "it": {0, 1, 2} "what": {0, 1} "what is it" "what" "is" "it" {0,1} ⋂ {0,1,2} ⋂ {0,1,2} = {0,1} "it is what it is", "what is it"
  9. elasticsearch Real time data Real time analytics Distributed High availability

    Multi-tenancy Full text search JSON Document oriented Conflict management Schema free RESTful API Build on top of Apache Lucene
  10. elasticsearch CRUD curl -XPUT http://localhost:9200/blog/article/1 -d '{ "title": "New version

    of Elastic Search released!", "content": "...", "tags": ["announce", "elasticsearch", "release"] }'
  11. FOSElasticaBundle External serializer (JMSserializer) Persistence: orm, mongodb, propel Native repositories

    Custom query builder: repo method Pagination: Pagerfanta, KnpPaginator
  12. FOSElasticaBundle External serializer (JMSserializer) fos_elastica: clients: default: { host: localhost,

    port: 9200 } serializer: callback_class: FOS\ElasticaBundle\Serializer\Callback serializer: serializer indexes: website: client: default types: user: mappings: username: { boost: 5 } firstName: { boost: 3 } lastName: { boost: 3 } aboutMe: ~
  13. FOSElasticaBundle Persistence: orm, mongodb, propel fos_elastica: clients: default: { host:

    localhost, port: 9200 } serializer: callback_class: FOS\ElasticaBundle\Serializer\Callback serializer: serializer indexes: website: client: default types: user: mappings: username: { boost: 5 } firstName: { boost: 3 } # more mappings... persistence: driver: mongodb model: Application\UserBundle\Document\User provider: ~
  14. FOSElasticaBundle Custom query builder: repo method persistence: driver: mongod model:

    Application\UserBundle\Document\User provider: query_builder_method: createIsActiveQueryBuilder
  15. FOSElasticaBundle Pagination: Pagerfanta, KnpPaginator $finder = $container->get('fos_elastica.finder.website.user'); /* Pagerfanta */

    $userPaginator = $finder->findPaginated('bob'); /* Knp paginator */ $paginator = $this->get('knp_paginator'); $userPaginator = $paginator ->paginate($finder->createPaginatorAdapter('bob'));
  16. FOSElasticaBundle Search $finder = $this->container->get('fos_elastica.finder.website.article'); $boolQuery = new \Elastica\Query\Bool(); $fieldQuery

    = new \Elastica\Query\Text(); $fieldQuery->setFieldQuery('title', 'I am a title string'); $fieldQuery->setFieldParam('title', 'analyzer', 'my_analyzer'); $boolQuery->addShould($fieldQuery); $tagsQuery = new \Elastica\Query\Terms(); $tagsQuery->setTerms('tags', array('tag1', 'tag2')); $boolQuery->addShould($tagsQuery); $categoryQuery = new \Elastica\Query\Terms(); $categoryQuery->setTerms('categoryIds', array('1', '2', '3')); $boolQuery->addMust($categoryQuery); $data = $finder->find($boolQuery);