Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-11244

Query DSL for Solr

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 7.1
    • None
    • None

    Description

      It will be great if Solr has a powerful query DSL. This ticket is an extension of http://yonik.com/solr-json-request-api/.

      Here are several examples of Query DSL

      curl -XGET http://localhost:8983/solr/query -d '
      {
          "query" : {
              "lucene" : {
                  "df" : "content",
                  "query" : "solr lucene"
              }
          }
      }
      

      the above example can be rewritten as (because lucene is the default qparser)

      curl -XGET http://localhost:8983/solr/query -d '
      {
          "query" : "content:(solr lucene)"
      }
      

      more complex example:

      curl -XGET http://localhost:8983/solr/query -d '
      { 
          "query" : {
              "boost" : {
                  "query" : {
                      "lucene" : {
                          "q.op" : "AND",
                          "df" : "cat_s",
                          "query" : "A"
                      }
                  }
                  "b" : "log(popularity)"
              }
          }
      }
      

      I call it Json Query Object (JQO) and It defined as :

      • It can be a valid query string for Lucene query parser, for example : "title:solr"
      • It can be a valid local parameters string, for example : " {!dismax qf=myfield}

        solr rocks"

      • It can be a json object with structure like this
        {
          "query-parser-name" : {
             "param1" : "value1",
             "param2" : "value2",
             "query" : <JQO>,
             "another-param" : <JQO>
          }
        }
        

        Therefore the above dismax query can be rewritten as ( be noticed that the query argument in local parameters, is put as value of query field )

        {
          "dismax" : {
             "qf" : "myfield"
             "query" : "solr rocks"
          }
        }
        

      I will attach an HTML, contain more examples of Query DSL.

      Attachments

        1. SOLR-11244.patch
          17 kB
          Cao Manh Dat
        2. SOLR-11244.patch
          16 kB
          Cao Manh Dat
        3. SOLR-11244.patch
          14 kB
          Cao Manh Dat
        4. SOLR-11244.patch
          10 kB
          Cao Manh Dat
        5. Solr Query DSL - examples.html
          78 kB
          Cao Manh Dat

        Issue Links

          Activity

            People

              caomanhdat Cao Manh Dat
              caomanhdat Cao Manh Dat
              Votes:
              2 Vote for this issue
              Watchers:
              14 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h 20m
                  2h 20m