Note that there are some explanatory texts on larger screens.

plurals
  1. POElasticSearch query failing due to state codes "in" and "or" being reserved words
    primarykey
    data
    text
    <p>I'm querying for states using the state code as the query string, and "in" and "or" (Indiana and Oregon) are failing, presumably because they're reserved words.</p> <p>I can confirm that the data exists in the index correctly, because when I run:</p> <pre><code>curl -XGET 'localhost:9200/state/_search?size=200&amp;pretty=true' -d '{"query" : {"match_all" : {}}}' &gt; out.txt </code></pre> <p>I can see the data there for both the working states and the non-working states. Plus, if I change the state code of a non-working state in CouchDB to something like XYZ, I can verify that the change makes it to ES by running the above command and searching for XYZ. So I know I'm looking at the right data and it's indexing fine.</p> <p>The problem is the query. Right now, here's what my entire query object looks like:</p> <pre><code>var q = { size: 0, query: { filtered: { query: { term: { postcode: 'tn' } }, filter: { term: { version: 2 } } } }, facets: { version: { terms: { field: "version" } }, count : { statistical : { field : "latestValues.enroll" } } } }; </code></pre> <p>If I run that query, I get no results. If I change the "or" out with "tn" or "tx" or "sc" etc., then it works fine.</p> <p>I looked for a way to escape reserved words and found <a href="http://elasticsearch-users.115913.n3.nabble.com/Searching-for-a-reserved-word-OR-td2238889.html" rel="nofollow">this link</a> but it doesn't seem to work for me, when running the following query:</p> <pre><code>var q = { size: 0, query: { filtered: { query: { match_all: { } }, filter: { term: { version: 2, postcode: 'or' } } } }, facets: { version: { terms: { field: "version" } }, count : { statistical : { field : "latestValues.enroll" } } } }; </code></pre> <p>(Note that that query also works when changing out "or" with a non-reserved-word-state so I know it's not a problem with the query itself).</p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload