Term query confusion


(David Jensen-2) #1

I ran a term query and didn't get the expected results. So I read
through some of the past conversations, looked up Lucene TermQuery and
I'm still a little confused about what's going wrong. It seems what
I'm doing should work.

ElasticSearch version: 0.8.0

Sample document being indexed:
{
"name": "David Jensen",
"validationDateString": "2010-07-26T11:09:10",
"title": "Engineering",
"companyName": "Spoke Software, Inc.",
"urls": ["http://www.spoke.com", "http://www.spokepay.com", "http://
www.spokesoftware.com/"],
"sicCodes": ["7371","8742","7374"],
"cities": ["San Mateo"],
"states": ["CA"],
"businessSummary": "Business contacts and networking..."
}

The following query returns zero results:
curl -XPOST 'http://localhost:9200/spokeprofile/person/_search' -d
'{ "query":{ "term":{"name": "Jensen"} } }'

The following queries return exactly 4011 results:
curl -XPOST 'http://localhost:9200/spokeprofile/person/_search' -d
'{ "query":{ "field":{"name": "Jensen"} } }'
curl -XPOST 'http://localhost:9200/spokeprofile/person/_search' -d
'{ "query":{ "query_string":{"default_field":"name",
"query":"Jensen"} } }'
curl -XPOST 'http://localhost:9200/spokeprofile/person/_search?
q=name:Jensen'


(ppearcy) #2

The inputs to a term query are not analyzed, implying that it must
match the exact term as stored in the index.

What analysis happens to the 'name' field on the index side?

If you used a non-lowercasing white space analyzer that should match.
I assume your analyzer is lower casing, so searching on term 'jenson'
should work.

Field queries are analyzed, which is why that works.

On Jul 26, 4:47 pm, David Jensen djense...@gmail.com wrote:

I ran a term query and didn't get the expected results. So I read
through some of the past conversations, looked up Lucene TermQuery and
I'm still a little confused about what's going wrong. It seems what
I'm doing should work.

ElasticSearch version: 0.8.0

Sample document being indexed:
{
"name": "David Jensen",
"validationDateString": "2010-07-26T11:09:10",
"title": "Engineering",
"companyName": "Spoke Software, Inc.",
"urls": ["http://www.spoke.com", "http://www.spokepay.com", "http://www.spokesoftware.com/"],
"sicCodes": ["7371","8742","7374"],
"cities": ["San Mateo"],
"states": ["CA"],
"businessSummary": "Business contacts and networking..."

}

The following query returns zero results:
curl -XPOST 'http://localhost:9200/spokeprofile/person/_search'-d
'{ "query":{ "term":{"name": "Jensen"} } }'

The following queries return exactly 4011 results:
curl -XPOST 'http://localhost:9200/spokeprofile/person/_search'-d
'{ "query":{ "field":{"name": "Jensen"} } }'
curl -XPOST 'http://localhost:9200/spokeprofile/person/_search'-d
'{ "query":{ "query_string":{"default_field":"name",
"query":"Jensen"} } }'
curl -XPOST 'http://localhost:9200/spokeprofile/person/_search?
q=name:Jensen'


(system) #3