The Graph explore API enables you to extract and summarize information about the documents and terms in your Elasticsearch index.
The easiest way to understand the behaviour of this API is to use the
Graph UI to explore connections. You can view the most recent request submitted
to the _explore
endpoint from the Last request panel. For more information,
see Getting Started with Graph.
For additional information about working with the explore API, see the Graph Troubleshooting and Limitations topics.
POST <index>/_graph/explore
An initial request to the _explore
API contains a seed query that identifies
the documents of interest and specifies the fields that define the vertices
and connections you want to include in the graph. Subsequent _explore
requests
enable you to spider out from one more vertices of interest. You can exclude
vertices that have already been returned.
A seed query that identifies the documents of interest. Can be any valid Elasticsearch query. For example:
"query": { "bool": { "must": { "match": { "query.raw": "midi" } }, "filter": [ { "range": { "query_time": { "gte": "2015-10-01 00:00:00" } } } ] } }
Specifies or more fields that contain the terms you want to include in the graph as vertices. For example:
"vertices": [ { "field": "product" } ]
term
and boost
values to boost matches on particular terms.
exclude
clause prevents the specified terms from being included in
the results.
Specifies or more fields from which you want to extract terms that are associated with the specified vertices. For example:
Connections can be nested inside the connections
object to
explore additional relationships in the data. Each level of nesting is
considered a hop, and proximity within the graph is often described in
terms of hop depth.
Contains the fields you are interested in. For example:
"vertices": [ { "field": "query.raw", "size": 5, "min_doc_count": 10, "shard_min_doc_count": 3 } ]
Direct the Graph API how to build the graph.
use_significance
flag filters associated terms so only those that are
significantly associated with your query are included. For information about
the algorithm used to calculate significance, see the
significant_terms
aggregation. Defaults to true
.
To avoid the top-matching documents sample being dominated by a single source of results, it is sometimes necessary to request diversity in the sample. You can do this by selecting a single-value field and setting a maximum number of documents per value for that field. For example:
"sample_diversity": { "field": "category.raw", "max_docs_per_value": 500 }
An initial search typically begins with a query to identify strongly related terms.
POST clicklogs/_graph/explore { "query": { "match": { "query.raw": "midi" } }, "vertices": [ { "field": "product" } ], "connections": { "vertices": [ { "field": "query.raw" } ] } }
Seed the exploration with a query. This example is searching clicklogs for people who searched for the term "midi". | |
Identify the vertices to include in the graph. This example is looking for product codes that are significantly associated with searches for "midi". | |
Find the connections. This example is looking for other search terms that led people to click on the products that are associated with searches for "midi". |
The response from the explore API looks like this:
{ "took": 0, "timed_out": false, "failures": [], "vertices": [ { "field": "query.raw", "term": "midi cable", "weight": 0.08745858139552132, "depth": 1 }, { "field": "product", "term": "8567446", "weight": 0.13247784285434397, "depth": 0 }, { "field": "product", "term": "1112375", "weight": 0.018600718471158982, "depth": 0 }, { "field": "query.raw", "term": "midi keyboard", "weight": 0.04802242866755111, "depth": 1 } ], "connections": [ { "source": 0, "target": 1, "weight": 0.04802242866755111, "doc_count": 13 }, { "source": 2, "target": 3, "weight": 0.08120623870976627, "doc_count": 23 } ] }
An array of all of the vertices that were discovered. A vertex is an indexed
term, so the field and term value are provided. The | |
The connections between the vertices in the array. The |
The default settings are configured to remove noisy data and get the "big picture" from your data. This example shows how to specify additional parameters to influence how the graph is built.
For tips on tuning the settings for more detailed forensic evaluation where every document could be of interest, see the Troubleshooting guide.
POST clicklogs/_graph/explore { "query": { "match": { "query.raw": "midi" } }, "controls": { "use_significance": false, "sample_size": 2000, "timeout": 2000, "sample_diversity": { "field": "category.raw", "max_docs_per_value": 500 } }, "vertices": [ { "field": "product", "size": 5, "min_doc_count": 10, "shard_min_doc_count": 3 } ], "connections": { "query": { "bool": { "filter": [ { "range": { "query_time": { "gte": "2015-10-01 00:00:00" } } } ] } }, "vertices": [ { "field": "query.raw", "size": 5, "min_doc_count": 10, "shard_min_doc_count": 3 } ] } }
Disable | |
Increase the sample size to consider a larger set of documents on each shard. | |
Limit how long a graph request runs before returning results. | |
Ensure diversity in the sample by setting a limit on the number of documents per value in a particular single-value field, such as a category field. | |
Control the maximum number of vertex terms returned for each field. | |
Set a certainty threshold that specifies how many documents have to contain a pair of terms before we consider it to be a useful connection. | |
Specify how many documents on a shard have to contain a pair of terms before the connection is returned for global consideration. | |
Restrict which document are considered as you explore connected terms. |
After an initial search, you typically want to select vertices of interest and see what additional vertices are connected. In graph-speak, this operation is referred to as "spidering". By submitting a series of requests, you can progressively build a graph of related information.
To spider out, you need to specify two things:
You specify this information using include`and `exclude
clauses. For example,
the following request starts with the product 1854873
and spiders
out to find additional search terms associated with that product. The terms
"midi", "midi keyboard", and "synth" are excluded from the results.