match_phrase
This example match_phrase query matches documents where the name contains the exact phrase THIS OPERATING AGREEMENT. First we show the query then the response. Then we explain some of the parameters and response attributes at the bottom of this page.
query curl
curl -X POST "https://www.lawinsider.com/api/v1alpha/search?token=$token&pretty" -H 'Content-Type: application/json' -d'{
"query": {
"bool": {
"must": [
{
"match_phrase": {
"name": {
"query": "THIS OPERATING AGREEMENT"
}
}
}
]
}
},
"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>"
]
}
}'
response JSON
{
"took" : 14,
"timed_out" : false,
"_shards" : {
"total" : 42,
"successful" : 42,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 115,
"relation" : "eq"
},
"max_score" : 8.4716625,
"hits" : [
{
"_index" : "contract",
"_type" : "_doc",
"_id" : "en/hgCi2HcOCoT",
"_score" : 8.4716625,
"_source" : {
"snippet" : "NOW THEREFORE THIS AGREEMENT WITNESSETH that in consideration of the premises and the mutual covenants and agreements hereinafter set forth, the parties hereto agree each with the other as follows:",
"group_size" : 1,
"group_id" : "hgCi2HcOCoT",
"filing_date" : "2014-11-12",
"jurisdiction" : {
"name" : "Nevada",
"value" : "nevada-us"
},
"name" : "THIS OPERATING AGREEMENT made the 11th day of November, 2014 (the \"Execution Date\").",
"industry" : {
"name" : "Metal mining",
"value" : "metal-mining"
},
"company" : {
"name" : "Lexaria Corp.",
"value" : "1348362"
},
"category" : {
"name" : "Operating Agreement",
"value" : "operating-agreement"
}
},
"highlight" : {
"name" : [
"<b>THIS</b> <b>OPERATING</b> <b>AGREEMENT</b> made the 11th day of November, 2014 (the \"Execution Date\")."
]
}
}
]
}
}
Parameters and Attributes
match_phrase query
ElasticSearch has many text-searching type of queries. One is match_phrase
.
First, notice that the query attribute is at the top. Also notice that since we are using curl
and since this query is wrapped across multiple lines we delimit the JSON payload with a tick mark (`) at the beginning and end.
Notice also that this is a bool boolean type query. We explain boolean queries here.
The match_phrase query is different than the match query. Match looks at the whole field as one. match_phrase matches single words or phrases in the query.
"query": {
"bool": {
"must": [
{
"match_phrase": {
"name": {
"query": "THIS OPERATING AGREEMENT"
}
}
}
]
}
}
highlight
The highlight prints the matching attribute in a separate section called highlight.
If we did not use the highlight section it would print all the fields in the source section. Since contracts can be very long it would show the clauses. Thats would be hard to read. So we highlight just the matching part of the query.
This is designed so that you can then list matching sections (snippets) it in a screen and it not be too long.
Notice the post_tags and pre_tags. This lets you wrap that in HTML to put emphasis on it.
post_filter
You need to use post_filter to limits queries to the index you want to query. The indexes are:
-
contract
-
clause
-
definition
-
company
-
category
"post_filter": {
"term": {
"_index": "contract"
}
}
_score
_score
basically means how well the query matched the document. This non-negative integer can be manipulated by various rules that boost
the score to a higher value. There are various reasons for doing that, such as pushing certain search results to the top of the list.
Updated over 1 year ago