simple_query_string

Use simple_query_string to search an attribute using or, and, etc. It is, like the name says, the simplest text operator.

Query Example

curl -X POST "https://www.lawinsider.com/api/v1alpha/search?token=$token&pretty" -H 'Content-Type: application/json' -d'{
    "query": {
  "bool": {
     "must": [
          {
              "simple_query_string": {
                  "default_operator": "or",
                  "fields": [
                      "name",
                      "snippet",
                      "body",
                      "company.name",
                      "jurisdiction.name"
                  ],
                  "query": "abc"
              }
          }
      ]
    }
  },
    "post_filter": {
        "term": {
            "_index": "contract"
        }
    },
    "size": 1,
    "profile": false,
    "explain": false,
    "timeout": "15000ms",
    "_source": [
        "name",
        "snippet",
        "category.name",
        "category.value",
        "company.name",
        "company.value",
        "jurisdiction.name",
        "jurisdiction.value",
        "industry.name",
        "industry.value",
        "filing_date",
        "group_id",
        "group_size"
    ],
    "highlight": {
        "fields": {
            "name": {}
        },
        "order": "score",
        "post_tags": [
            "</b>"
        ],
        "pre_tags": [
            "<b>"
        ]
    }
}'

results

{
  "took" : 87,
  "timed_out" : false,
  "_shards" : {
    "total" : 42,
    "successful" : 42,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 3397,
      "relation" : "eq"
    },
    "max_score" : 41.156113,
    "hits" : [
      {
        "_index" : "contract",
        "_type" : "_doc",
        "_id" : "en/MEmXhMxef5",
        "_score" : 41.156113,
        "_source" : {
          "snippet" : "This Electric Sales Agreement (\"Agreement\"), number 12345 (agreement ID) is entered into between ABC Energy Services, L.L.C. (\"ABC\") and John Smith (\"Customer\"). This Agreement shall be effective as of the date signed by ABC and indicated as the \"Effective Date\" on ABC’s signature block hereto and not prior thereto. ABC and Customer may be individually referred to as \"Party\" or collectively referred to as \"Parties.\" The Parties agree to the following:",
          "group_size" : 1,
          "group_id" : "MEmXhMxef5",
          "filing_date" : "2015-07-15",
          "jurisdiction" : {
            "name" : "Illinois",
            "value" : "illinois-us"
          },
          "name" : "ABC ENERGY SERVICES L.L.C. ELECTRIC SALES AGREEMENT",
          "industry" : {
            "name" : "Electric services",
            "value" : "electric-services"
          },
          "company" : {
            "name" : "Premier Holding Corp.",
            "value" : "1030916"
          },
          "category" : {
            "name" : "Sales Agreement",
            "value" : "sales-agreement"
          }
        },
        "highlight" : {
          "name" : [
            "<b>ABC</b> ENERGY SERVICES L.L.C. ELECTRIC SALES AGREEMENT"
          ]
        }
      }
    ]
  }
}

Parameters

query and query syntax

You can user different operators like:

  • or (a | b)
  • and (a + b)
  • not (-a)
  • and others

If you use any of those you would not need the parameter default_operator.

Plus you can use a wildcard (*).

Embedded quotes muse be escaped like \".

              "query": "abc"
          }
      }
  ]
}

bool, filter, must

It is common practice to use bool followed by filter. And bool must be follow by must, must_not, or other operators.

       {
    "query": {
  "bool": {
      "filter": [],
      "must": [
          {
              "simple_query_string": {

fields

Fields to search. You need to put this as you are not allowed to a raw search of the entire document.

              "fields": [
                  "name",
                  "snippet",
                  "body",
                  "company.name",
                  "jurisdiction.name"
              ],

You can boost the relevance of fields using the caret, like name^3