Docs Menu
Docs Home
/
MongoDB Atlas
/ / /

Lucene Query Structured Summary

The explain response of a search command contains information about the query executed with that command. The response includes structured details of what Lucene queries Atlas Search executed to satisfy a $search query.

This page contains:

  • Some of the Lucene queries that Atlas Search operators create

  • Lucene query options that are included in the structured summary

  • Lucene query structured summary example for each Lucene query type

Note

About the Examples

The examples in this section are based on queries run against the sample datasets with the queryPlanner verbosity mode. In the example response, the:

  • mongotQuery field shows the Atlas Search operator and the query that was run.

  • explain.type field shows the Lucene Query that the operator created.

For complete examples, see Examples.

BooleanQuery

For Lucene BooleanQuery, the structured summary includes details on the following options:

Field
Type
Necessity
Description

must

Optional

Clauses which must match.

mustNot

Optional

Clauses which must not match.

should

Optional

Clauses which should match.

filter

Optional

Clauses which must all match.

minimumShouldMatch

Integer

Optional

The minimum number of should clauses which must match.

The following example shows the explain response for a query run against the sample_airbnb.listingsAndReviews collection.

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "compound" : {
7 "must" : [ {
8 "compound" : {
9 "should" : [ {
10 "text" : {
11 "query" : "historic",
12 "path" : "summary"
13 }
14 },
15 {
16 "text" : {
17 "query" : "Portugal",
18 "path" : "address.country"
19 }
20 },
21 {
22 "text" : {
23 "query" : "railway",
24 "path" : "transit"
25 }
26 } ]
27 }
28 } ],
29 "mustNot" : [ {
30 "text" : {
31 "query" : "Apartment",
32 "path" : "property_type"
33 }
34 } ]
35 }
36 },
37 "explain" : {
38 "type" : "BooleanQuery",
39 "args" : {
40 "must" : [ {
41 "path" : "compound.must",
42 "type" : "BooleanQuery",
43 "args" : {
44 "must" : [ ],
45 "mustNot" : [ ],
46 "should" : [
47 {
48 "path" : "compound.must.compound.should[0]",
49 "type" : "TermQuery",
50 "args" : {
51 "path" : "summary",
52 "value" : "historic"
53 }
54 },
55 {
56 "path" : "compound.must.compound.should[1]",
57 "type" : "TermQuery",
58 "args" : {
59 "path" : "address.country",
60 "value" : "portugal"
61 }
62 },
63 {
64 "path" : "compound.must.compound.should[2]",
65 "type" : "TermQuery",
66 "args" : {
67 "path" : "transit",
68 "value" : "railway"
69 }
70 }
71 ],
72 "filter" : [ ],
73 "minimumShouldMatch" : 0
74 }
75 } ],
76 "mustNot" : [ {
77 "path" : "compound.mustNot",
78 "type" : "TermQuery",
79 "args" : {
80 "path" : "property_type",
81 "value" : "apartment"
82 }
83 } ],
84 "should" : [ ],
85 "filter" : [ ],
86 "minimumShouldMatch" : 0
87 }
88 }
89 },
90 ...
91 },
92 ...
93 ],
94 ...
95}
ConstantScoreQuery

For constant score queries, the structured summary includes details on the following options:

Field
Type
Necessity
Description

query

Required

Child of the ConstantScoreQuery.

The following example shows the explain response for a query run against the sample_airbnb.listingsAndReviews collection.

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "equals" : {
7 "path" : "host.host_identity_verified",
8 "value" : true
9 }
10 },
11 "explain" : {
12 "type" : "ConstantScoreQuery",
13 "args" : {
14 "query" : {
15 "type" : "TermQuery",
16 "args" : {
17 "path" : "host.host_identity_verified",
18 "value" : "T"
19 }
20 }
21 }
22 }
23 }
24 },
25 {
26 "$_internalSearchIdLookup" : { }
27 }
28 ],
29 ...
30}
FunctionScoreQuery

For Lucene FunctionScoreQuery queries, the structured summary includes details on the following options:

Field
Type
Necessity
Description

scoreFunction

string

Required

Scoring expression used in the query.

query

Required

The query.

The following example shows the explain response for a query run against the sample_airbnb.listingsAndReviews collection.

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "near" : {
7 "path" : "accomodates",
8 "origin" : 8,
9 "pivot" : 2
10 }
11 },
12 "explain" : {
13 "type" : "BooleanQuery",
14 "args" : {
15 "must" : [ ],
16 "mustNot" : [ ],
17 "should" : [
18 {
19 "type" : "BooleanQuery",
20 "args" : {
21 "must" : [ ],
22 "mustNot" : [ ],
23 "should" : [
24 {
25 "type" : "FunctionScoreQuery",
26 "args" : {
27 "scoreFunction" : "expr(pivot / (pivot + abs(origin - value)))",
28 "query" : {
29 "type" : "LongDistanceFeatureQuery",
30 "args" : { },
31 "stats" : { }
32 }
33 }
34 }
35 ],
36 "filter" : [
37 {
38 "type" : "PointRangeQuery",
39 "args" : {
40 "path" : "accomodates",
41 "representation" : "double",
42 "gte" : 8.000000000000002,
43 "lte" : NaN
44 }
45 }
46 ],
47 "minimumShouldMatch" : 0
48 }
49 },
50 {
51 "type" : "LongDistanceFeatureQuery",
52 "args" : { },
53 "stats" : { }
54 }
55 ],
56 "filter" : [ ],
57 "minimumShouldMatch" : 0
58 }
59 }
60 },
61 ...
62 },
63 ...
64 ],
65 ...
66}
LatLonPointDistanceQuery

For Lucene LatLonPointDistanceQuery queries, the response contains an Explain Timing Breakdown only.

The following example shows the explain response for a query run against the sample_airbnb.listingsAndReviews collection.

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "geoWithin" : {
7 "path" : "address.location",
8 "circle" : {
9 "radius" : 4800,
10 "center" : {
11 "type" : "Point",
12 "coordinates" : [
13 -122.419472,
14 37.765302
15 ]
16 }
17 }
18 }
19 },
20 "explain" : {
21 "type" : "LatLonPointDistanceQuery",
22 "args" : { }
23 }
24 }
25 },
26 ...
27 ],
28 ...
29}
LatLonShapeQuery

For Lucene LatLonShapeQuery queries, the response contains an Explain Timing Breakdown only.

The following example shows the explain response for a query run against the sample_airbnb.listingsAndReviews collection.

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "geoShape" : {
7 "path" : "address.location",
8 "relation" : "within",
9 "geometry" : {
10 "type" : "Polygon",
11 "coordinates" : [
12 [
13 [ -74.3994140625, 40.5305017757 ],
14 [ -74.7290039063, 40.5805846641 ],
15 [ -74.7729492188, 40.9467136651 ],
16 [ -74.0698242188, 41.1290213475 ],
17 [ -73.65234375, 40.9964840144 ],
18 [ -72.6416015625, 40.9467136651 ],
19 [ -72.3559570313, 40.7971774152 ],
20 [ -74.3994140625, 40.5305017757 ]
21 ]
22 ]
23 }
24 }
25 },
26 "explain" : {
27 "type" : "LatLonShapeQuery",
28 "args" : { }
29 }
30 },
31 ...
32 },
33 ...
34 ],
35 ...
36}
LongDistanceFeatureQuery

For Lucene LongDistanceFeatureQuery, the response contains an Explain Timing Breakdown only.

The following example shows the explain response for a query run against the sample_mflix.movies collection.

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "near" : {
7 "path" : "released",
8 "origin" : ISODate("1915-09-13T00:00:00Z"),
9 "pivot" : 7776000000
10 }
11 },
12 "explain" : {
13 "type" : "LongDistanceFeatureQuery",
14 "args" : { }
15 }
16 },
17 ...
18 },
19 ...
20 ],
21 ...
22}
MultiTermQueryConstantScoreWrapper

For Lucene MultiTermQueryConstantScoreWrapper queries, the structured summary includes details on the following arguments:

Field
Type
Necessity
Description

queries

Required

List of queries.

The following example shows the explain response for a query run against the sample_airbnb.listingsAndReviews collection.

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "regex" : {
7 "path" : "access",
8 "query" : "full(.{0,5})",
9 "allowAnalyzedField" : true
10 }
11 },
12 "explain" : {
13 "type" : "MultiTermQueryConstantScoreWrapper",
14 "args" : {
15 "queries" : [
16 {
17 "type" : "DefaultQuery",
18 "args" : {
19 "queryType" : "RegexpQuery"
20 }
21 }
22 ]
23 }
24 }
25 },
26 ...
27 },
28 ...
29 ],
30 ...
31}
PhraseQuery

For Lucene PhraseQuery queries, the structured summary includes details on the following arguments:

Field
Type
Necessity
Description

path

string

Required

Indexed field to search.

query

string

Required

String or strings to search for.

slop

int

Required

Allowable distance between words in the query phrase.

The following example shows the explain response for a query run against the sample_airbnb.listingsAndReviews collection.

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "phrase" : {
7 "path" : "description",
8 "query" : "comfortable apartment",
9 "slop" : 2
10 }
11 },
12 "explain" : {
13 "type" : "PhraseQuery",
14 "args" : {
15 "path" : "description",
16 "query" : "[comfortable, apartment]",
17 "slop" : 2
18 }
19 }
20 },
21 ...
22 },
23 ...
24 ],
25 ...
26}
PointRangeQuery

For Lucene PointRangeQuery queries, the structured summary includes details on the following arguments:

Field
Type
Necessity
Description

path

string

Required

Indexed field to search.

representation

string

Optional

Numeric representation. Queries over date-typed data do not include representation.

gte

number

Optional

Lower bound of the query.

lte

number

Optional

Upper bound of the query.

The following example shows the explain response for a query run against the sample_airbnb.listingsAndReviews collection.

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "range" : {
7 "path" : "number_of_reviews",
8 "gt" : 5
9 }
10 },
11 "explain" : {
12 "type" : "BooleanQuery",
13 "args" : {
14 "must" : [ ],
15 "mustNot" : [ ],
16 "should" : [
17 {
18 "type" : "PointRangeQuery",
19 "args" : {
20 "path" : "number_of_reviews",
21 "representation" : "double",
22 "gte" : 5.000000000000001
23 }
24 },
25 {
26 "type" : "PointRangeQuery",
27 "args" : {
28 "path" : "number_of_reviews",
29 "representation" : "int64",
30 "gte" : NumberLong(6)
31 }
32 }
33 ],
34 "filter" : [ ],
35 "minimumShouldMatch" : 0
36 }
37 }
38 },
39 ...
40 },
41 ...
42 ],
43 ...
44}
TermQuery

For term queries, the structured summary includes details on the following arguments:

Field
Type
Necessity
Description

path

string

Required

Indexed field to search.

value

string

Required

String to search for.

The following example shows the explain response for a query run against the sample_airbnb.listingsAndReviews collection.

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "queryString" : {
7 "defaultPath" : "summary",
8 "query" : "quiet"
9 }
10 },
11 "explain" : {
12 "type" : "TermQuery",
13 "args" : {
14 "path" : "summary",
15 "value" : "quiet"
16 }
17 }
18 },
19 ...
20 },
21 ...
22 ],
23 ...
24}
Default

Lucene queries that are not explicitly defined by another Lucene query are serialized using the default query. The structured summary includes details on the following option:

Field
Type
Necessity
Description

queryType

string

Required.

Type of Lucene query.

The following example shows the explain response for a query run against the sample_airbnb.listingsAndReviews collection.

1{
2 "stages" : [
3 {
4 "$_internalSearchMongotRemote" : {
5 "mongotQuery" : {
6 "near" : {
7 "origin" : {
8 "type" : "Point",
9 "coordinates" : [
10 -8.61308,
11 41.1413
12 ]
13 },
14 "pivot" : 1000,
15 "path" : "address.location"
16 }
17 },
18 "explain" : {
19 "type" : "DefaultQuery",
20 "args" : {
21 "queryType" : "LatLonPointDistanceFeatureQuery"
22 }
23 }
24 },
25 ...
26 },
27 ...
28 ],
29 ...
30}