Combining routing and filter

(Daniel Duarte Figueiredo) #1

I am having problems using a terms filter when I specify the routing value.
I'm indexing documents called "activities" routing by the user's ID. I
decided changing the default routing since I will always list activities by
the user ID, so I thought using this field as the routing value would be
useful. But when I execute the following command:


I get documents from more than one user. For example, activities from user
with ID = 1 are allocated in the same shard as activities from user with ID
= 6. So, to list only the activities from the user I want, I have to use a
terms filter, but it is not working.

I am using NEST (ES C# wrapper), so I don't know if it's a bug in NEST, or
if I am using it wrong, or if it's how elastic search works. Can anyone
answer me that?

The code I'm using with NEST is:

private static void Index(Activity activity)
GetClient().Index(activity, activityIndexName, "activity",
new IndexParameters() { Routing = activity.userID.ToString() });

public static IList ListUserActivities(int userID)
return GetClient().Search(s => s
.Filter(q => q
.Term("userID", userID.ToString()))

(Clinton Gormley) #2

I have to use a terms filter, but it is not working.

What does a real userID look like, and how is the userID mapped. I'm
betting that the field is just mapped as { type: "string" }, which means
that the value is being analyzed, and that your UIDs include capital
letters, which means that they are being stored lowercase.

A term filter won't work in this situation because you are searching for
"XYZ123" but the value that is stored is actually "xyz123"

You should set your userID to be:

{ type: "string", index: "not_analyzed" }


(system) #3