Skip to content

Instantly share code, notes, and snippets.

@FabioBatSilva
Last active August 29, 2015 14:08
Show Gist options
  • Save FabioBatSilva/d2b06d8f2851012d44cb to your computer and use it in GitHub Desktop.
Save FabioBatSilva/d2b06d8f2851012d44cb to your computer and use it in GitHub Desktop.
Query flat data when indexing a document with conceptually many 'children':
{
"id": 1,
"username": "Box2Account",
"profiles": [
{
"id": "24029",
"gender": "1",
"birthday": "1982-05-03T04:00:00Z"
},
{
"id": "40170",
"gender": "2",
"birthday": "1970-01-01T05:00:00Z"
}
]
}
{
"responseHeader": {
"status": 0,
"QTime": 13,
"params": {}
},
"response": {
"numFound": 1,
"start": 0,
"maxScore": 1,
"docs": [
{
"profiles.birthday": [
"1982-05-03T04:00:00Z",
"1970-01-01T05:00:00Z"
],
"profiles.gender": [
1,
2
],
"profiles.id": [
24029,
40170
],
"_yz_id": "1*default*ac_test*1*57",
"_yz_rk": "1",
"_yz_rt": "default",
"_yz_rb": "ac_test"
}
]
}
}
<?xml version="1.0" encoding="UTF-8"?>
<schema name="account_schema" version="1.5">
<fields>
<field name="id" type="long" indexed="true" stored="false" />
<field name="username" type="string" indexed="true" stored="false" />
<field name="profiles.id" type="long" indexed="true" stored="true" multiValued="true"/>
<field name="profiles.gender" type="int" indexed="true" stored="true" multiValued="true"/>
<field name="profiles.birthday" type="date" indexed="true" stored="true" multiValued="true" />
<dynamicField name="*" type="ignored" />
<!-- All of these fields are required by Riak Search -->
<field name="_yz_id" type="_yz_str" indexed="true" stored="true" multiValued="false" required="true" />
<field name="_yz_ed" type="_yz_str" indexed="true" stored="false" multiValued="false" />
<field name="_yz_pn" type="_yz_str" indexed="true" stored="false" multiValued="false" />
<field name="_yz_fpn" type="_yz_str" indexed="true" stored="false" multiValued="false" />
<field name="_yz_vtag" type="_yz_str" indexed="true" stored="false" multiValued="false" />
<field name="_yz_rk" type="_yz_str" indexed="true" stored="true" multiValued="false" />
<field name="_yz_rt" type="_yz_str" indexed="true" stored="true" multiValued="false" />
<field name="_yz_rb" type="_yz_str" indexed="true" stored="true" multiValued="false" />
<field name="_yz_err" type="_yz_str" indexed="true" stored="false" multiValued="false" />
</fields>
<uniqueKey>_yz_id</uniqueKey>
<types>
<!-- YZ String: Used for non-analyzed fields -->
<fieldType name="_yz_str" class="solr.StrField" sortMissingLast="true" />
<fieldType name="string" class="solr.StrField" sortMissingLast="true" positionIncrementGap="100"/>
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" positionIncrementGap="100"/>
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="100"/>
<fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="100"/>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="100"/>
<fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="100"/>
<fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="100"/>
<fieldtype name="ignored" stored="false" indexed="false" multiValued="true" class="solr.StrField" />
</types>
</schema>
@FabioBatSilva
Copy link
Author

curl -XGET "http://...?wt=json&q=profiles.id:24029&fq=profiles.gender:2"

Profile 24029 is gender 1, it should not match

FieldMaskingSpanQuery seems to be the solution http://www.solr-start.com/javadoc/solr-lucene/org/apache/lucene/search/spans/FieldMaskingSpanQuery.html

But how to use FieldMaskingSpanQuery as a query string ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment