Skip to content

Instantly share code, notes, and snippets.

@artaa
Created December 20, 2011 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artaa/1502438 to your computer and use it in GitHub Desktop.
Save artaa/1502438 to your computer and use it in GitHub Desktop.
no search hits after disabling _all field
Came from: http://elasticsearch-users.115913.n3.nabble.com/Elastic-Search-Query-td3535843.html
$ curl -XDELETE 'http://localhost:9200/topic1/'
{"ok":true,"acknowledged":true}
$ curl -XPUT 'http://localhost:9200/topic1/'
{"ok":true,"acknowledged":true}
$ curl -XPUT 'http://localhost:9200/topic1/DefaultType/_mapping' -d '{ "DefaultType" : { "properties": { "content": { "type": "string" }, "time_modified": { "type": "date" } }, "_all": { "enabled": false }, "_source": { "compress": true } } }'
{"ok":true,"acknowledged":true}
$ curl -XPUT 'http://localhost:9200/topic1/DefaultType/1' -d '{ "content": "aaa bbb ccc ddd", "time_modified": "2011-12-20T09:20" }'
{"ok":true,"_index":"topic1","_type":"DefaultType","_id":"1","_version":1}$
$ curl -XGET 'http://localhost:9200/topic1/_search?pretty=true' -d '{ "query": { "term": { "default_field": "content", "query": "bbb" } } }'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
$ curl -XGET 'http://localhost:9200/topic1/_search?pretty=true' -d '{ "query": { "wildcard": { "default_field": "content", "query": "*" } } }'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
$ curl -XGET 'http://localhost:9200/topic1/_search?pretty=true' -d '{ "query": { "match_all": { } } }'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "topic1",
"_type" : "DefaultType",
"_id" : "1",
"_score" : 1.0, "_source" : { "content": "aaa bbb ccc ddd", "time_modified": "2011-12-20T09:20" }
} ]
}
}
$ curl -XGET 'http://localhost:9200/topic1/_mapping?pretty=true'
{
"topic1" : {
"DefaultType" : {
"_source" : {
"compress" : true
},
"properties" : {
"content" : {
"type" : "string"
},
"time_modified" : {
"format" : "dateOptionalTime",
"type" : "date"
}
},
"_all" : {
"enabled" : false
}
}
}
}
@kimchy
Copy link

kimchy commented Dec 20, 2011

All the queries used here (like term) syntax is incorrect. You specify the field you want to query in them. The one supporting default_field is query_string, because of its special query string syntax. Here is an example:

curl 'localhost:9200/topic1/_search?pretty=1' -d '{
    "query" : {
        "query_string" : {
            "default_field" : "content",
            "query" : "aaa"
        }
    }
}'

@artaa
Copy link
Author

artaa commented Dec 20, 2011

Thanks kimchy,
So you mean once _all is disabled, queries we can use are limited to match_all and query_string?

@kimchy
Copy link

kimchy commented Dec 21, 2011

No, thats not what I mean, where did I say that? Here is the doc for term query: http://www.elasticsearch.org/guide/reference/query-dsl/term-query.html, the user part there is the field name, it has no concept of default field. You need to tell it which field to query on anyhow.

@artaa
Copy link
Author

artaa commented Dec 21, 2011

Thanks for the quick response.
I'm referring to the discussion board
http://elasticsearch-users.115913.n3.nabble.com/Elastic-Search-Query-td3535843.html
where you explained:

What is your search request? Note, you need to specify a default field to search against if you disable _all.
This is why I tried "default_field" even for "term" query. Because with _all field disabled, the regular query form did not work.
Maybe I misunderstood. What did you mean by "default field" in that context?

@kimchy
Copy link

kimchy commented Dec 21, 2011

The response there only applies to query_string query, where the default value for default_field is _all. And if you disable it, you need to explicitly set another field.

@artaa
Copy link
Author

artaa commented Dec 21, 2011

I see now. Thank you so much for clearing it out.
It turned out I did wrong at the first place when I tried to disable _all. I used Java API and mistakingly did like this:
client.admin().indices().preparePutMapping("index1").setType("type1").setSource("{"_all": {"enabled": false }}").execute()
I thought I didn't need to give the type name again in the source because it was given to setType(). But it was not correct. (right?)
Because of this mistake, I was not able to hit any query, so I came to this page and saw your response mentioning about 'default field'.
Anyway, the problem solved.
Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment