Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@janhoy
Created January 11, 2018 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janhoy/45640fe3bad696d53ef8a0930a35d163 to your computer and use it in GitHub Desktop.
Save janhoy/45640fe3bad696d53ef8a0930a35d163 to your computer and use it in GitHub Desktop.
nested-problem
  1. Create an index

     solr create -c nested
    
  2. Index two documents, where one is nested.

     curl localhost:8983/solr/a/update -d '<add>
        <doc>
          <field name="id">friend</field>
          <field name="type">other</field>
        </doc>
        <doc>
          <field name="id">mother</field>
          <field name="type">parent</field>
          <doc>
            <field name="id">daughter</field>
            <field name="type">child</field>
          </doc>
        </doc>
      </add>'
    
  3. Search for children of "mother"

     curl "localhost:8983/solr/a/query?q=id:mother&fl=%2A%2C%5Bchild%20parentFilter%3Dtype%3Aparent%5D” 
    

    You get "friend" mistakenly in the list of children

  4. Now index same two docs again, but in opposite order

     curl localhost:8983/solr/a/update -d '<add>
        <doc>
          <field name="id">mother</field>
          <field name="type">parent</field>
          <doc>
            <field name="id">daughter</field>
            <field name="type">child</field>
          </doc>
        </doc>
        <doc>
          <field name="id">friend</field>
          <field name="type">other</field>
        </doc>
      </add>'
    
  5. Search again

     curl "localhost:8983/solr/a/query?q=id:mother&fl=%2A%2C%5Bchild%20parentFilter%3Dtype%3Aparent%5D” 
    

    You now only get "daughter" as child of "mother"

Why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment