0

I have one document in Elastic Search:

{
   "accountGroupId":1000,
   "name":"Elastic Burgers",
   "capacity":33,
   "startTime":1391604480000,
   "address":{
      "streetName":"Rua Carlos Petit",
      "streetNumber":"111",
      "complement":"",
      "neighborhood":"Vila Mariana",
      "city":"São Paulo",
      "state":"SP",
      "country":"Brasil",
      "zip":"04110000",
      "position":{
         "latitude":-23.5845048,
         "longitude":-46.6358975
      },
      "accountGroupId":1000,
      "status":[

      ],
      "id":1000,
      "createTime":1391010548111,
      "updateTime":1391010548111
   },
   "flyerUrl":"/assets/images/placeholder-merchant.png",
   "backgroundImageUrl":"/assets/images/placeholder-merchant.png",
   "onSaleStartTime":1391604480000,
   "onSaleEndTime":1392990480000,
   "description":"Lorem Ipsum",
   "eventCategoryId":1000,
   "deleted":false,
   "installmentId":100,
   "feeId":101,
   "restricted":false,
   "venueAccountGroupId":15,
   "updateTime":1391691790113,
   "createTime":1391691790113,
   "id":1002,
   "venue":"Acme, Inc.",
   "category":"Festa Faculdade"
}

This REST query returns the document:

curl -XGET 'http://localhost:9200/paguemob/events/_search' -d '{
    "query": {
        "multi_match" : {
            "query" : "festa de faculdade",
            "fields" : ["name", "address.city", "venue", "category", "description"]
        }    
    }
}'

But if I run the equivalent query via the Java API, the result is empty:

client
  .prepareSearch(index)
  .setQuery(multiMatchQuery("festa de faculdade", "name", "address.city", "venue", "category", "description"))
  .setSize(200)
  .execute()
  .actionGet()
  .getHits

What am I doing wrong?

0

2 Answers 2

1

Looking at some of the ES test code I see that in addition to the multiMatchQuery itself they also set OR as the operator (I would assume that is the default) and useDisMax to false, and set the type.

   searchResponse = client().prepareSearch("test")
   .setQuery(multiMatchQuery("marvel hero captain america", "full_name", "first_name", "last_name", "category")
   .operator(MatchQueryBuilder.Operator.OR).useDisMax(false).type(type)).get();

I wonder if one of those is the trick?

Also, your example may not show it but are you accessing the hit results array in Java correctly?

searchResponse.getHits().hits()[0]
Sign up to request clarification or add additional context in comments.

1 Comment

The OR operator is the default one, as for the dismax that affects the way the scores are computed, but it doesn't seem to be the reason why the doc is not returned.
0

I spotted the error: I had not set the type for the search. So, adding a .setTypes("events") to the call did the trick.

1 Comment

Weird, do you have other types under the same index?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.