I am updating a project to store metadata in ES for enhanced searching. The 
server is currently fixed to ES 1.2.1.

Locally, I have a ES node with the Marvel plugin so I can access the sense 
editor to run queries. I have a unit test that is populating data into ES. 
The data is formatted such as

            "_source": {
               "protocol": "my-protocol",
               "right": "my-right",
               "type": "my-type",
               "address": [
                  "my-hostname"
               ]
            }


My goal is to build a query that will search for multiple addresses that 
are all optional; think of it as the various IPs and names associated with 
a single server.

In Java, I am building a set of match queries that are joined with boolean 
should. Here is some of the code.

            Set<String> addresses = findHostAddresses(criteria.getHost());
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery(); 

            for (String address : addresses) 
            { 
                boolBuilder.should(QueryBuilders.matchQuery(
CredentialManagerSearchConstants.FIELD_ADDRESS, address.toLowerCase())); 
            }


This is then wrapped once more with a boolean must query clause to find a 
specific result based on address and one or more of the other fields. If I 
look at the constructed query in my debugger, the query looks like the 
following.

  "bool" : {
   "must" : {
    "bool" : {
     "should" : [ {
      "match" : {
       "address" : {
        "query" : "host1",
        "type" : "boolean"
                 }
                }
      },{
       "match" : {
        "address" : {
         "query" : "host2",
         "type" : "boolean"
                   }
                  }
       } ]
              }
            }
      }


I use a SearchRequestBuilder and set my index, type and the noFields flag 
(I don't need the data, just the ID). For my simple case, I know that I 
have a record with a particular address in it. If I search for a single 
address only using a single match, the Java bindings work correctly. If I 
search for multiple addresses like the above, then the result is not found.

I thought this may just be a problem with how I am constructing the query. 
I took the output from my debugger on the query itself and used the marvel 
sense plugin to execute that exact query through the REST API. Here is an 
example of the query from marvel sense.

GET /my-index/my-type/_search
{
  "query": {
    "bool": {
      "must": {
        "bool": {
          "should": [
            {
              "match": {
                "address": {
                  "query": "host1",
                  "type": "boolean"
                }
              }
            },
            {
              "match": {
                "address": {
                  "query": "host2",
                  "type": "boolean"
                }
              }
            }
          ]
        }
      }
    }
  }
}

Using the REST API, the one document that I have in my sample indexed 
document set is returned without issue.


It is entirely possible that I am using the Java APIs incorrectly. The 
documentation for these APIs is not always that useful.

Are there any reports of the native or transport protocols behaving 
differently than the REST protocol? That appears to be what is happening 
here.


As a test, I ran the latest 1.3 and 1.4 versions of ES through my unit 
tests and the behavior is still the same in those versions.

Thanks. 

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/688fdc29-07f6-4073-b6da-bbc58fde6419%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to