Prefix searching

I can't seem to get prefix searching to work at all. I'm using the
Java API with the following:

QueryBuilder qb = QueryBuilders.boolQuery()
.must(QueryBuilders.prefixQuery("Path","/Marcus/"));

SearchResponse response = client.prepareSearch("objects")
.setQuery(qb)
.setExplain(true)
.execute()
.actionGet();

SearchHits sh = response.getHits();

System.out.println("Num of results: " + sh.getTotalHits());

I get zero results every time and the data definitely fits the query.
I assume that the above search would return a record with a "Path"
value of "/Marcus/Example". This record exists and so do many others
like it.

I haven't tuned ElasticSearch at all and I don't know if this requires
explicit indexing, but it doesn't work via ElasticSearch Head either
so I think it must be on the server side.

Thanks for any help.

IMO I think that with default mapping, your field "path" is tokenized. You should use a keyword analyzer for this field if you don't want it to be tokenized.

A prefix search on "marcus" with default mapping should give you results.

Hope this helps.

David :wink:

Le 21 août 2011 à 01:23, marcuslongmuir marcuslongmuir@me.com a écrit :

I can't seem to get prefix searching to work at all. I'm using the
Java API with the following:

QueryBuilder qb = QueryBuilders.boolQuery()
.must(QueryBuilders.prefixQuery("Path","/Marcus/"));

SearchResponse response = client.prepareSearch("objects")
.setQuery(qb)
.setExplain(true)
.execute()
.actionGet();

SearchHits sh = response.getHits();

System.out.println("Num of results: " + sh.getTotalHits());

I get zero results every time and the data definitely fits the query.
I assume that the above search would return a record with a "Path"
value of "/Marcus/Example". This record exists and so do many others
like it.

I haven't tuned Elasticsearch at all and I don't know if this requires
explicit indexing, but it doesn't work via Elasticsearch Head either
so I think it must be on the server side.

Thanks for any help.

Thanks for the advice David. I've only just started using
Elasticsearch, could you explain how to do this?

From your explanation I understand that the field is being indexed
only as the keywords, which in this case means that I can't use
prefix to find records that begin with the exact string.

Assuming no configuration, what do I need to set in order for the
following to occur?

Index records with "Path" values:
"/Marcus/Example/One"
"/Marcus/Example/"
"/Marcus/"

And these be returned when I use a prefix search with the value "/
Marcus/".

Thanks

On Aug 21, 1:47 am, David Pilato da...@pilato.fr wrote:

IMO I think that with default mapping, your field "path" is tokenized. You should use a keyword analyzer for this field if you don't want it to be tokenized.

A prefix search on "marcus" with default mapping should give you results.

Hope this helps.

David :wink:

Le 21 août 2011 à 01:23, marcuslongmuir marcuslongm...@me.com a écrit :

I can't seem to get prefix searching to work at all. I'm using the
Java API with the following:

QueryBuilder qb = QueryBuilders.boolQuery()
.must(QueryBuilders.prefixQuery("Path","/Marcus/"));

SearchResponse response = client.prepareSearch("objects")
.setQuery(qb)
.setExplain(true)
.execute()
.actionGet();

SearchHits sh = response.getHits();

System.out.println("Num of results: " + sh.getTotalHits());

I get zero results every time and the data definitely fits the query.
I assume that the above search would return a record with a "Path"
value of "/Marcus/Example". This record exists and so do many others
like it.

I haven't tuned Elasticsearch at all and I don't know if this requires
explicit indexing, but it doesn't work via Elasticsearch Head either
so I think it must be on the server side.

Thanks for any help.

I've just got it working how I intended, but I couldn't work out how
to do it via Java and just did it via CURL with the following:

curl -XPUT 'http://127.0.0.1:9200/objects/object/_mapping' -d
'{"object" : {"properties" : { "Path" : {"type":"string", "index" :
"not_analyzed"}}}}'

Although I've solved the exact issue I was having, how would I go
about doing this in Java?

I like to define my mappings as json files since it allows me to put them
into source control:

In Java, you can either:

There are probably other ways to do it.

--
Ivan

On Sat, Aug 20, 2011 at 11:01 PM, marcuslongmuir marcuslongmuir@me.comwrote:

I've just got it working how I intended, but I couldn't work out how
to do it via Java and just did it via CURL with the following:

curl -XPUT 'http://127.0.0.1:9200/objects/object/_mapping' -d
'{"object" : {"properties" : { "Path" : {"type":"string", "index" :
"not_analyzed"}}}}'

Although I've solved the exact issue I was having, how would I go
about doing this in Java?